Skip to content

Commit c9d803a

Browse files
committed
coding style
1 parent 925b93b commit c9d803a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+999
-697
lines changed

ncs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<ruleset name="Custom" namespace="Nette">
3-
<rule ref="$presets/php72.xml"/>
3+
<rule ref="$presets/php80.xml"/>
44

55
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly">
66
<exclude-pattern>./tests/*/*.phpt</exclude-pattern>

src/CodeCoverage/Collector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static function start(string $file, string $engine): void
5454
} elseif (!in_array(
5555
$engine,
5656
array_map(fn(array $engineInfo) => $engineInfo[0], self::detectEngines()),
57-
true
57+
true,
5858
)) {
5959
throw new \LogicException("Code coverage engine '$engine' is not supported.");
6060
}

src/CodeCoverage/Generators/AbstractGenerator.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public function __construct(string $file, array $sources = [])
4444
throw new \Exception("Content of file '$file' is invalid.");
4545
}
4646

47-
$this->data = array_filter($this->data, function (string $path): bool {
48-
return @is_file($path); // @ some files or wrappers may not exist, i.e. mock://
49-
}, ARRAY_FILTER_USE_KEY);
47+
$this->data = array_filter($this->data, fn(string $path): bool => @is_file($path), ARRAY_FILTER_USE_KEY);
5048

5149
if (!$sources) {
5250
$sources = [Helpers::findCommonDirectory(array_keys($this->data))];
@@ -102,14 +100,15 @@ protected function getSourceIterator(): \Iterator
102100
$iterator->append(
103101
is_dir($source)
104102
? new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source))
105-
: new \ArrayIterator([new \SplFileInfo($source)])
103+
: new \ArrayIterator([new \SplFileInfo($source)]),
106104
);
107105
}
108106

109-
return new \CallbackFilterIterator($iterator, function (\SplFileInfo $file): bool {
110-
return $file->getBasename()[0] !== '.' // . or .. or .gitignore
111-
&& in_array($file->getExtension(), $this->acceptFiles, true);
112-
});
107+
return new \CallbackFilterIterator(
108+
$iterator,
109+
fn(\SplFileInfo $file): bool => $file->getBasename()[0] !== '.' // . or .. or .gitignore
110+
&& in_array($file->getExtension(), $this->acceptFiles, true)
111+
);
113112
}
114113

115114

src/Framework/Assert.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public static function exception(
298298
callable $function,
299299
string $class,
300300
?string $message = null,
301-
$code = null
301+
$code = null,
302302
): ?\Throwable
303303
{
304304
self::$counter++;
@@ -332,7 +332,7 @@ public static function throws(
332332
callable $function,
333333
string $class,
334334
?string $message = null,
335-
mixed $code = null
335+
mixed $code = null,
336336
): ?\Throwable
337337
{
338338
return self::exception($function, $class, $message, $code);
@@ -346,7 +346,7 @@ public static function throws(
346346
public static function error(
347347
callable $function,
348348
int|string|array $expectedType,
349-
?string $expectedMessage = null
349+
?string $expectedMessage = null,
350350
): ?\Throwable
351351
{
352352
if (is_string($expectedType) && !preg_match('#^E_[A-Z_]+$#D', $expectedType)) {
@@ -474,7 +474,7 @@ public static function fail(
474474
$actual = null,
475475
$expected = null,
476476
?\Throwable $previous = null,
477-
?string $outputName = null
477+
?string $outputName = null,
478478
): void
479479
{
480480
$e = new AssertException($message, $expected, $actual, $previous);
@@ -584,7 +584,7 @@ public static function expandMatchingPatterns(string $pattern, string $actual):
584584
$high = strlen($actual);
585585
while ($low <= $high) {
586586
$mid = ($low + $high) >> 1;
587-
if (!self::isMatching($patternX, substr($actual, 0, $mid), true)) {
587+
if (!self::isMatching($patternX, substr($actual, 0, $mid), strict: true)) {
588588
$high = $mid - 1;
589589
} else {
590590
$low = $mid + 1;
@@ -611,7 +611,7 @@ private static function isEqual(
611611
bool $matchOrder,
612612
bool $matchIdentity,
613613
int $level = 0,
614-
?\SplObjectStorage $objects = null
614+
?\SplObjectStorage $objects = null,
615615
): bool
616616
{
617617
switch (true) {

src/Framework/DataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function load(string $file, string $query = ''): array
3434
throw new \Exception("Data provider '$file' did not return array or Traversable.");
3535
}
3636
} else {
37-
$data = @parse_ini_file($file, true); // @ is escalated to exception
37+
$data = @parse_ini_file($file, process_sections: true); // @ is escalated to exception
3838
if ($data === false) {
3939
throw new \Exception("Cannot parse data provider file '$file'.");
4040
}

src/Framework/DomQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function fromHtml(string $html): self
2828
$html = preg_replace_callback(
2929
'#(<script(?=\s|>)(?:"[^"]*"|\'[^\']*\'|[^"\'>])*+>)(.*?)(</script>)#s',
3030
fn(array $m): string => $m[1] . str_replace('</', '<\/', $m[2]) . $m[3],
31-
$html
31+
$html,
3232
);
3333

3434
$dom = new \DOMDocument;

src/Framework/Dumper.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static function toLine(mixed $var): string
3838
return "$var";
3939

4040
} elseif (is_float($var)) {
41-
return var_export($var, true);
41+
return var_export($var, return: true);
4242

4343
} elseif (is_string($var)) {
4444
if (preg_match('#^(.{' . self::$maxLength . '}).#su', $var, $m)) {
@@ -138,7 +138,7 @@ private static function _toPhp(mixed &$var, array &$list = [], int $level = 0, i
138138

139139
static $marker;
140140
if ($marker === null) {
141-
$marker = uniqid("\x00", true);
141+
$marker = uniqid("\x00", more_entropy: true);
142142
}
143143

144144
if (empty($var)) {
@@ -221,7 +221,7 @@ private static function _toPhp(mixed &$var, array &$list = [], int $level = 0, i
221221
return '/* resource ' . get_resource_type($var) . ' */';
222222

223223
} else {
224-
return var_export($var, true);
224+
return var_export($var, return: true);
225225
}
226226
}
227227

@@ -238,12 +238,10 @@ private static function encodeStringPhp(string $s): string
238238
$utf8 = preg_match('##u', $s);
239239
$escaped = preg_replace_callback(
240240
$utf8 ? '#[\p{C}\\\\]#u' : '#[\x00-\x1F\x7F-\xFF\\\\]#',
241-
function ($m) use ($special) {
242-
return $special[$m[0]] ?? (strlen($m[0]) === 1
243-
? '\x' . str_pad(strtoupper(dechex(ord($m[0]))), 2, '0', STR_PAD_LEFT) . ''
244-
: '\u{' . strtoupper(ltrim(dechex(self::utf8Ord($m[0])), '0')) . '}');
245-
},
246-
$s
241+
fn($m) => $special[$m[0]] ?? (strlen($m[0]) === 1
242+
? '\x' . str_pad(strtoupper(dechex(ord($m[0]))), 2, '0', STR_PAD_LEFT) . ''
243+
: '\u{' . strtoupper(ltrim(dechex(self::utf8Ord($m[0])), '0')) . '}'),
244+
$s,
247245
);
248246
return $s === str_replace('\\\\', '\\', $escaped)
249247
? "'" . preg_replace('#\'|\\\\(?=[\'\\\\]|$)#D', '\\\\$0', $s) . "'"
@@ -263,14 +261,12 @@ private static function encodeStringLine(string $s): string
263261
$utf8 = preg_match('##u', $s);
264262
$escaped = preg_replace_callback(
265263
$utf8 ? '#[\p{C}\']#u' : '#[\x00-\x1F\x7F-\xFF\']#',
266-
function ($m) use ($special) {
267-
return "\e[22m"
268-
. ($special[$m[0]] ?? (strlen($m[0]) === 1
269-
? '\x' . str_pad(strtoupper(dechex(ord($m[0]))), 2, '0', STR_PAD_LEFT)
270-
: '\u{' . strtoupper(ltrim(dechex(self::utf8Ord($m[0])), '0')) . '}'))
271-
. "\e[1m";
272-
},
273-
$s
264+
fn($m) => "\e[22m"
265+
. ($special[$m[0]] ?? (strlen($m[0]) === 1
266+
? '\x' . str_pad(strtoupper(dechex(ord($m[0]))), 2, '0', STR_PAD_LEFT)
267+
: '\u{' . strtoupper(ltrim(dechex(self::utf8Ord($m[0])), '0')) . '}'))
268+
. "\e[1m",
269+
$s,
274270
);
275271
return "'" . $escaped . "'";
276272
}
@@ -326,7 +322,7 @@ public static function dumpException(\Throwable $e): string
326322
for (; $i && $i < strlen($actual) && $actual[$i - 1] >= "\x80" && $actual[$i] >= "\x80" && $actual[$i] < "\xC0"; $i--);
327323
$i = max(0, min(
328324
$i - (int) (self::$maxLength / 3), // try to display 1/3 of shorter string
329-
max(strlen($actual), strlen($expected)) - self::$maxLength + 3 // 3 = length of ...
325+
max(strlen($actual), strlen($expected)) - self::$maxLength + 3, // 3 = length of ...
330326
));
331327
if ($i) {
332328
$expected = substr_replace($expected, '...', 0, $i);
@@ -370,7 +366,7 @@ public static function dumpException(\Throwable $e): string
370366
($item['file'] === $testFile ? self::color('white') : '')
371367
. implode(
372368
self::$pathSeparator ?? DIRECTORY_SEPARATOR,
373-
array_slice(explode(DIRECTORY_SEPARATOR, $item['file']), -self::$maxPathSegments)
369+
array_slice(explode(DIRECTORY_SEPARATOR, $item['file']), -self::$maxPathSegments),
374370
)
375371
. "($item[line])" . self::color('gray') . ' '
376372
)

src/Framework/Environment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static function setupColors(): void
9494
ob_start(
9595
fn(string $s): string => self::$useColors ? $s : Dumper::removeColors($s),
9696
1,
97-
PHP_OUTPUT_HANDLER_FLUSHABLE
97+
PHP_OUTPUT_HANDLER_FLUSHABLE,
9898
);
9999
}
100100

src/Framework/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function run(): void
3737

3838
$methods = array_values(preg_grep(
3939
self::MethodPattern,
40-
array_map(fn(\ReflectionMethod $rm): string => $rm->getName(), (new \ReflectionObject($this))->getMethods())
40+
array_map(fn(\ReflectionMethod $rm): string => $rm->getName(), (new \ReflectionObject($this))->getMethods()),
4141
));
4242

4343
if (isset($_SERVER['argv']) && ($tmp = preg_filter('#--method=([\w-]+)$#Ai', '$1', $_SERVER['argv']))) {
@@ -145,7 +145,7 @@ public function runTest(string $method, ?array $args = null): void
145145
$e->origMessage,
146146
$method->getName(),
147147
substr(Dumper::toLine($params), 1, -1),
148-
is_string($k) ? (" (data set '" . explode('-', $k, 2)[1] . "')") : ''
148+
is_string($k) ? (" (data set '" . explode('-', $k, 2)[1] . "')") : '',
149149
));
150150
}
151151
}

src/Runner/CliTester.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private function loadOptions(): CommandLine
140140
throw new \Exception(
141141
$file === null
142142
? 'Option -o <format> without file name parameter can be used only once.'
143-
: "Cannot specify output by -o into file '$file' more then once."
143+
: "Cannot specify output by -o into file '$file' more then once.",
144144
);
145145
} elseif ($file === null) {
146146
$this->stdoutFormat = $format;
@@ -150,19 +150,19 @@ private function loadOptions(): CommandLine
150150

151151
return [$format, $file];
152152
}],
153-
]
153+
],
154154
);
155155

156156
if (isset($_SERVER['argv'])) {
157-
if (($tmp = array_search('-l', $_SERVER['argv'], true))
158-
|| ($tmp = array_search('-log', $_SERVER['argv'], true))
159-
|| ($tmp = array_search('--log', $_SERVER['argv'], true))
157+
if (($tmp = array_search('-l', $_SERVER['argv'], strict: true))
158+
|| ($tmp = array_search('-log', $_SERVER['argv'], strict: true))
159+
|| ($tmp = array_search('--log', $_SERVER['argv'], strict: true))
160160
) {
161161
$_SERVER['argv'][$tmp] = '-o';
162162
$_SERVER['argv'][$tmp + 1] = 'log:' . $_SERVER['argv'][$tmp + 1];
163163
}
164164

165-
if ($tmp = array_search('--tap', $_SERVER['argv'], true)) {
165+
if ($tmp = array_search('--tap', $_SERVER['argv'], strict: true)) {
166166
unset($_SERVER['argv'][$tmp]);
167167
$_SERVER['argv'] = array_merge($_SERVER['argv'], ['-o', 'tap']);
168168
}
@@ -223,7 +223,7 @@ private function createRunner(): Runner
223223
$runner,
224224
(bool) $this->options['-s'],
225225
'php://output',
226-
(bool) $this->options['--cider']
226+
(bool) $this->options['--cider'],
227227
);
228228
}
229229

src/Runner/Job.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function run(bool $async = false): void
109109
$pipes,
110110
dirname($this->test->getFile()),
111111
null,
112-
['bypass_shell' => true]
112+
['bypass_shell' => true],
113113
);
114114

115115
foreach (array_keys($this->envVars) as $name) {
@@ -124,7 +124,7 @@ public function run(bool $async = false): void
124124
}
125125

126126
if ($async) {
127-
stream_set_blocking($this->stdout, false); // on Windows does not work with proc_open()
127+
stream_set_blocking($this->stdout, enable: false); // on Windows does not work with proc_open()
128128
} else {
129129
while ($this->isRunning()) {
130130
usleep(self::RunSleep); // stream_select() doesn't work with proc_open()

src/Runner/Output/ConsolePrinter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
Runner $runner,
3838
bool $displaySkipped = false,
3939
?string $file = null,
40-
bool $ciderMode = false
40+
bool $ciderMode = false,
4141
) {
4242
$this->runner = $runner;
4343
$this->displaySkipped = $displaySkipped;
@@ -74,7 +74,7 @@ public function prepare(Test $test): void
7474
} elseif (!str_starts_with($test->getFile(), $this->baseDir)) {
7575
$common = array_intersect_assoc(
7676
explode(DIRECTORY_SEPARATOR, $this->baseDir),
77-
explode(DIRECTORY_SEPARATOR, $test->getFile())
77+
explode(DIRECTORY_SEPARATOR, $test->getFile()),
7878
);
7979
$this->baseDir = '';
8080
$prev = 0;

src/Runner/Output/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function end(): void
7676
. ($this->results[Test::Failed] ? ", {$this->results[Test::Failed]} failures" : '')
7777
. ($this->results[Test::Skipped] ? ", {$this->results[Test::Skipped]} skipped" : '')
7878
. ($this->count !== $run ? ', ' . ($this->count - $run) . ' not run' : '')
79-
. ')'
79+
. ')',
8080
);
8181
}
8282
}

src/Runner/PhpInterpreter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(string $path, array $args = [])
3232
$pipes,
3333
null,
3434
null,
35-
['bypass_shell' => true]
35+
['bypass_shell' => true],
3636
);
3737
if ($proc === false) {
3838
throw new \Exception("Cannot run PHP interpreter $path. Use -p option.");
@@ -55,7 +55,7 @@ public function __construct(string $path, array $args = [])
5555
$pipes,
5656
null,
5757
null,
58-
['bypass_shell' => true]
58+
['bypass_shell' => true],
5959
);
6060
$output = stream_get_contents($pipes[1]);
6161
$this->error = trim(stream_get_contents($pipes[2]));
@@ -66,7 +66,7 @@ public function __construct(string $path, array $args = [])
6666
$parts = explode("\r\n\r\n", $output, 2);
6767
$this->cgi = count($parts) === 2;
6868
$this->info = @unserialize((string) strstr($parts[$this->cgi], 'O:8:"stdClass"'));
69-
$this->error .= strstr($parts[$this->cgi], 'O:8:"stdClass"', true);
69+
$this->error .= strstr($parts[$this->cgi], 'O:8:"stdClass"', before_needle: true);
7070
if (!$this->info) {
7171
throw new \Exception("Unable to detect PHP version (output: $output).");
7272

src/Runner/TestHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private function initiateDataProvider(Test $test, string $provider): array|Test
157157

158158
return array_map(
159159
fn(string $item): Test => $test->withArguments(['dataprovider' => "$item|$dataFile"]),
160-
array_keys($data)
160+
array_keys($data),
161161
);
162162
}
163163

@@ -166,7 +166,7 @@ private function initiateMultiple(Test $test, string $count): array
166166
{
167167
return array_map(
168168
fn(int $i): Test => $test->withArguments(['multiple' => $i]),
169-
range(0, (int) $count - 1)
169+
range(0, (int) $count - 1),
170170
);
171171
}
172172

@@ -229,7 +229,7 @@ private function initiateTestCase(Test $test, $foo, PhpInterpreter $interpreter)
229229

230230
return array_map(
231231
fn(string $method): Test => $test->withArguments(['method' => $method]),
232-
$methods
232+
$methods,
233233
);
234234
}
235235

src/Runner/info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'sapi' => PHP_SAPI,
2020
'iniFiles' => array_merge(
2121
($tmp = php_ini_loaded_file()) === false ? [] : [$tmp],
22-
(function_exists('php_ini_scanned_files') && strlen($tmp = (string) php_ini_scanned_files())) ? explode(",\n", trim($tmp)) : []
22+
(function_exists('php_ini_scanned_files') && strlen($tmp = (string) php_ini_scanned_files())) ? explode(",\n", trim($tmp)) : [],
2323
),
2424
'extensions' => $extensions,
2525
'tempDir' => sys_get_temp_dir(),

tests/CodeCoverage/CloverXMLGenerator.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $coverageData = Tester\FileMock::create(serialize([
1717
$coveredDir . DIRECTORY_SEPARATOR . 'Logger.php' => array_map('intval', preg_filter(
1818
'~.*# (-?\d+)~',
1919
'$1',
20-
explode("\n", "\n" . file_get_contents($coveredDir . DIRECTORY_SEPARATOR . 'Logger.php'))
20+
explode("\n", "\n" . file_get_contents($coveredDir . DIRECTORY_SEPARATOR . 'Logger.php')),
2121
)),
2222
]));
2323

0 commit comments

Comments
 (0)