Skip to content

Commit 38d3044

Browse files
committed
cs
1 parent 54a435c commit 38d3044

17 files changed

+46
-33
lines changed

src/Utils/ArrayHash.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function from(array $array, bool $recursive = true): static
2929
$obj = new static;
3030
foreach ($array as $key => $value) {
3131
$obj->$key = $recursive && is_array($value)
32-
? static::from($value, true)
32+
? static::from($value)
3333
: $value;
3434
}
3535

src/Utils/Arrays.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static function mergeTree(array $array1, array $array2): array
9898
*/
9999
public static function getKeyOffset(array $array, string|int $key): ?int
100100
{
101-
return Helpers::falseToNull(array_search(self::toKey($key), array_keys($array), true));
101+
return Helpers::falseToNull(array_search(self::toKey($key), array_keys($array), strict: true));
102102
}
103103

104104

@@ -151,9 +151,9 @@ public static function last(array $array): mixed
151151
public static function insertBefore(array &$array, string|int|null $key, array $inserted): void
152152
{
153153
$offset = $key === null ? 0 : (int) self::getKeyOffset($array, $key);
154-
$array = array_slice($array, 0, $offset, true)
154+
$array = array_slice($array, 0, $offset, preserve_keys: true)
155155
+ $inserted
156-
+ array_slice($array, $offset, count($array), true);
156+
+ array_slice($array, $offset, count($array), preserve_keys: true);
157157
}
158158

159159

@@ -167,9 +167,9 @@ public static function insertAfter(array &$array, string|int|null $key, array $i
167167
$offset = count($array) - 1;
168168
}
169169

170-
$array = array_slice($array, 0, $offset + 1, true)
170+
$array = array_slice($array, 0, $offset + 1, preserve_keys: true)
171171
+ $inserted
172-
+ array_slice($array, $offset + 1, count($array), true);
172+
+ array_slice($array, $offset + 1, count($array), preserve_keys: true);
173173
}
174174

175175

src/Utils/FileSystem.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class FileSystem
2323
*/
2424
public static function createDir(string $dir, int $mode = 0777): void
2525
{
26-
if (!is_dir($dir) && !@mkdir($dir, $mode, true) && !is_dir($dir)) { // @ - dir may already exist
26+
if (!is_dir($dir) && !@mkdir($dir, $mode, recursive: true) && !is_dir($dir)) { // @ - dir may already exist
2727
throw new Nette\IOException(sprintf(
2828
"Unable to create directory '%s' with mode %s. %s",
2929
self::normalizePath($dir),

src/Utils/Html.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ public function insert(?int $index, HtmlStringable|string $child, bool $replace
628628
*/
629629
final public function offsetSet($index, $child): void
630630
{
631-
$this->insert($index, $child, true);
631+
$this->insert($index, $child, replace: true);
632632
}
633633

634634

src/Utils/ObjectHelpers.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ public static function strictCall(string $class, string $method, array $addition
6262
? ($trace[2]['class'] ?? null)
6363
: null;
6464

65-
if ($context && is_a($class, $context, true) && method_exists($context, $method)) { // called parent::$method()
65+
if (
66+
$context
67+
&& is_a($class, $context, allow_string: true)
68+
&& method_exists($context, $method)
69+
) { // called parent::$method()
6670
$class = get_parent_class($context);
6771
}
6872

@@ -95,7 +99,11 @@ public static function strictStaticCall(string $class, string $method): void
9599
? ($trace[2]['class'] ?? null)
96100
: null;
97101

98-
if ($context && is_a($class, $context, true) && method_exists($context, $method)) { // called parent::$method()
102+
if (
103+
$context
104+
&& is_a($class, $context, allow_string: true)
105+
&& method_exists($context, $method)
106+
) { // called parent::$method()
99107
$class = get_parent_class($context);
100108
}
101109

src/Utils/Type.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static function fromReflection(
3535
? $reflection->getReturnType() ?? (PHP_VERSION_ID >= 80100 && $reflection instanceof \ReflectionMethod ? $reflection->getTentativeReturnType() : null)
3636
: $reflection->getType();
3737

38-
return $type ? self::fromReflectionType($type, $reflection, true) : null;
38+
return $type ? self::fromReflectionType($type, $reflection, asObject: true) : null;
3939
}
4040

4141

@@ -49,7 +49,7 @@ private static function fromReflectionType(\ReflectionType $type, $of, bool $asO
4949

5050
} elseif ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType) {
5151
return new self(
52-
array_map(fn($t) => self::fromReflectionType($t, $of, false), $type->getTypes()),
52+
array_map(fn($t) => self::fromReflectionType($t, $of, asObject: false), $type->getTypes()),
5353
$type instanceof \ReflectionUnionType ? '|' : '&',
5454
);
5555

@@ -109,7 +109,7 @@ public static function resolve(
109109

110110
private function __construct(array $types, string $kind = '|')
111111
{
112-
$o = array_search('null', $types, true);
112+
$o = array_search('null', $types, strict: true);
113113
if ($o !== false) { // null as last
114114
array_splice($types, $o, 1);
115115
$types[] = 'null';
@@ -260,7 +260,7 @@ private function allows3(array $types, array $subtypes): bool
260260
$subtypes,
261261
fn($subtype) => Validators::isBuiltinType($type)
262262
? strcasecmp($type, $subtype) === 0
263-
: is_a($subtype, $type, true)
263+
: is_a($subtype, $type, allow_string: true)
264264
)
265265
);
266266
}

src/Utils/Validators.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static function assert(mixed $value, string $expected, string $label = 'v
102102
$translate = ['boolean' => 'bool', 'integer' => 'int', 'double' => 'float', 'NULL' => 'null'];
103103
$type = $translate[gettype($value)] ?? gettype($value);
104104
if (is_int($value) || is_float($value) || (is_string($value) && strlen($value) < 40)) {
105-
$type .= ' ' . var_export($value, true);
105+
$type .= ' ' . var_export($value, return: true);
106106
} elseif (is_object($value)) {
107107
$type .= ' ' . $value::class;
108108
}
@@ -245,7 +245,7 @@ public static function isNumeric(mixed $value): bool
245245
*/
246246
public static function isCallable(mixed $value): bool
247247
{
248-
return $value && is_callable($value, true);
248+
return $value && is_callable($value, syntax_only: true);
249249
}
250250

251251

tests/Utils/ArrayHash.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ test('', function () {
8787
'children' => [
8888
'c' => 'John',
8989
],
90-
], false);
90+
], recursive: false);
9191
Assert::type(Nette\Utils\ArrayHash::class, $list);
9292
Assert::type('array', $list['children']);
9393
});

tests/Utils/Arrays.flatten().phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $res = Arrays::flatten([
3535
],
3636
'y' => 'd',
3737
'z' => 'e',
38-
], true);
38+
], preserveKeys: true);
3939

4040
Assert::same([
4141
5 => 'a',

tests/Utils/Arrays.normalize.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ Assert::same(
3737
Arrays::normalize([
3838
1 => 'first',
3939
'' => 'second',
40-
], true),
40+
], filling: true),
4141
);

tests/Utils/Callback.check.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ require __DIR__ . '/../bootstrap.php';
1515

1616
Assert::same('trim', Callback::check('trim'));
1717

18-
Assert::same('undefined', Callback::check('undefined', true));
18+
Assert::same('undefined', Callback::check('undefined', syntax: true));
1919

2020

2121
Assert::exception(
22-
fn() => Callback::check(123, true),
22+
fn() => Callback::check(123, syntax: true),
2323
Nette\InvalidArgumentException::class,
2424
'Given value is not a callable type.',
2525
);
@@ -40,7 +40,7 @@ Assert::exception(
4040
);
4141

4242
Assert::exception(
43-
fn() => Callback::check(new stdClass, true),
43+
fn() => Callback::check(new stdClass, syntax: true),
4444
Nette\InvalidArgumentException::class,
4545
'Given value is not a callable type.',
4646
);

tests/Utils/FileSystem.copy.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ test('copy', function () {
5252
FileSystem::write(getTempDir() . '/5/newfile', 'World');
5353

5454
Assert::exception(
55-
fn() => FileSystem::copy(getTempDir() . '/5/newfile', getTempDir() . '/3/x/file', false),
55+
fn() => FileSystem::copy(getTempDir() . '/5/newfile', getTempDir() . '/3/x/file', overwrite: false),
5656
Nette\InvalidStateException::class,
5757
"File or directory '%a%' already exists.",
5858
);
5959
Assert::same('Hello', FileSystem::read(getTempDir() . '/3/x/file'));
6060

6161
Assert::exception(
62-
fn() => FileSystem::copy('remote://example.com', getTempDir() . '/3/x/file', false),
62+
fn() => FileSystem::copy('remote://example.com', getTempDir() . '/3/x/file', overwrite: false),
6363
Nette\InvalidStateException::class,
6464
"File or directory '%a%' already exists.",
6565
);
@@ -69,7 +69,7 @@ test('copy', function () {
6969
Assert::same('World', FileSystem::read(getTempDir() . '/3/x/file'));
7070

7171
Assert::exception(
72-
fn() => FileSystem::copy(getTempDir() . '/5', getTempDir() . '/3', false),
72+
fn() => FileSystem::copy(getTempDir() . '/5', getTempDir() . '/3', overwrite: false),
7373
Nette\InvalidStateException::class,
7474
"File or directory '%a%' already exists.",
7575
);

tests/Utils/FileSystem.rename.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test('rename file & dir', function () {
2222
test('overwrite file', function () {
2323
FileSystem::write(getTempDir() . '/8/newfile', 'World');
2424
Assert::exception(
25-
fn() => FileSystem::rename(getTempDir() . '/8/newfile', getTempDir() . '/9/x/file', false),
25+
fn() => FileSystem::rename(getTempDir() . '/8/newfile', getTempDir() . '/9/x/file', overwrite: false),
2626
Nette\InvalidStateException::class,
2727
"File or directory '%a%' already exists.",
2828
);
@@ -35,7 +35,7 @@ test('overwrite file', function () {
3535
test('overwrite dir', function () {
3636
FileSystem::createDir(getTempDir() . '/10/');
3737
Assert::exception(
38-
fn() => FileSystem::rename(getTempDir() . '/10', getTempDir() . '/9', false),
38+
fn() => FileSystem::rename(getTempDir() . '/10', getTempDir() . '/9', overwrite: false),
3939
Nette\InvalidStateException::class,
4040
"File or directory '%a%' already exists.",
4141
);

tests/Utils/Finder.basic.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ test('recursive file & directory search in child-first order', function () {
120120
Assert::same([
121121
'fixtures.finder/subdir/subdir2',
122122
'fixtures.finder/subdir',
123-
], export($finder, false));
123+
], export($finder, sort: false));
124124
});
125125

126126

tests/Utils/Strings.compare().phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Assert::true(Strings::compare('xy', 'yy', -1));
2626
Assert::true(Strings::compare("I\u{F1}t\u{EB}rn\u{E2}ti\u{F4}n\u{E0}liz\u{E6}ti\u{F8}n", "I\u{D1}T\u{CB}RN\u{C2}TI\u{D4}N\u{C0}LIZ\u{C6}TI\u{D8}N")); // Iñtërnâtiônàlizætiøn
2727
Assert::true(Strings::compare("I\u{F1}t\u{EB}rn\u{E2}ti\u{F4}n\u{E0}liz\u{E6}ti\u{F8}n", "I\u{D1}T\u{CB}RN\u{C2}TI\u{D4}N\u{C0}LIZ\u{C6}TI\u{D8}N", 10));
2828

29-
if (class_exists('Normalizer', false)) {
29+
if (class_exists('Normalizer')) {
3030
Assert::true(Strings::compare("\xC3\x85", "A\xCC\x8A"), 'comparing NFC with NFD form');
3131
Assert::true(Strings::compare("A\xCC\x8A", "\xC3\x85"), 'comparing NFD with NFC form');
3232
}

tests/Utils/Strings.normalize().phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Assert::same('Hello World', Strings::normalize("Hello \u{80} World"));
2424
Assert::same('Hello World', Strings::normalize("Hello \u{9F} World"));
2525
Assert::same("Hello \u{A0} World", Strings::normalize("Hello \u{A0} World"));
2626

27-
if (class_exists('Normalizer', false)) {
27+
if (class_exists('Normalizer')) {
2828
Assert::same("\xC3\x85", Strings::normalize("\xC3\x85")); // NFC -> NFC form
2929
Assert::same("\xC3\x85", Strings::normalize("A\xCC\x8A")); // NFD -> NFC form
3030
}

tests/Utils/Strings.webalize().phpt

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ declare(strict_types=1);
99
use Nette\Utils\Strings;
1010
use Tester\Assert;
1111

12-
1312
require __DIR__ . '/../bootstrap.php';
1413

1514

16-
Assert::same('zlutoucky-kun-oeooo', Strings::webalize("&\u{17D}LU\u{164}OU\u{10C}K\u{DD} K\u{16E}\u{147} \u{F6}\u{151}\u{F4}o!")); // &ŽLUŤOUČKÝ KŮŇ öőôo!
17-
Assert::same('ZLUTOUCKY-KUN-oeooo', Strings::webalize("&\u{17D}LU\u{164}OU\u{10C}K\u{DD} K\u{16E}\u{147} \u{F6}\u{151}\u{F4}o!", null, false)); // &ŽLUŤOUČKÝ KŮŇ öőôo!
15+
Assert::same(
16+
'zlutoucky-kun-oeooo',
17+
Strings::webalize('&ŽLUŤOUČKÝ KŮŇ öőôo!'),
18+
);
19+
Assert::same(
20+
'ZLUTOUCKY-KUN-oeooo',
21+
Strings::webalize('&ŽLUŤOUČKÝ KŮŇ öőôo!', lower: false),
22+
);
1823
if (class_exists('Transliterator') && Transliterator::create('Any-Latin; Latin-ASCII')) {
1924
Assert::same('1-4-!', Strings::webalize("\u{BC} !", '!'));
2025
}

0 commit comments

Comments
 (0)