refactor: PHP 8 features

This commit is contained in:
Nuno Maduro
2021-10-24 18:29:59 +01:00
parent e8c2fe6e35
commit 2b687a7269
43 changed files with 283 additions and 635 deletions

View File

@ -17,7 +17,7 @@ final class AfterAllRepository
/**
* @var array<string, Closure>
*/
private $state = [];
private array $state = [];
/**
* Runs the given closure for each after all.

View File

@ -18,7 +18,7 @@ final class AfterEachRepository
/**
* @var array<string, Closure>
*/
private $state = [];
private array $state = [];
/**
* Sets a after each closure.

View File

@ -17,7 +17,7 @@ final class BeforeAllRepository
/**
* @var array<string, Closure>
*/
private $state = [];
private array $state = [];
/**
* Runs one before all closure, and unsets it from the repository.

View File

@ -16,7 +16,7 @@ final class BeforeEachRepository
/**
* @var array<string, Closure>
*/
private $state = [];
private array $state = [];
/**
* Sets a before each closure.

View File

@ -30,12 +30,12 @@ final class TestRepository
/**
* @var array<string, TestCaseFactory>
*/
private $state = [];
private array $state = [];
/**
* @var array<string, array<int, array<int, string|Closure>>>
*/
private $uses = [];
private array $uses = [];
/**
* Counts the number of test cases.
@ -54,9 +54,7 @@ final class TestRepository
{
$testsWithOnly = $this->testsUsingOnly();
return array_values(array_map(function (TestCaseFactory $factory): string {
return $factory->filename;
}, count($testsWithOnly) > 0 ? $testsWithOnly : $this->state));
return array_values(array_map(fn (TestCaseFactory $factory): string => $factory->filename, count($testsWithOnly) > 0 ? $testsWithOnly : $this->state));
}
/**
@ -64,9 +62,7 @@ final class TestRepository
*/
public function build(TestSuite $testSuite, callable $each): void
{
$startsWith = function (string $target, string $directory): bool {
return Str::startsWith($target, $directory . DIRECTORY_SEPARATOR);
};
$startsWith = fn (string $target, string $directory): bool => Str::startsWith($target, $directory . DIRECTORY_SEPARATOR);
foreach ($this->uses as $path => $uses) {
[$classOrTraits, $groups, $hooks] = $uses;
@ -123,9 +119,7 @@ final class TestRepository
return [];
}
return array_filter($this->state, function ($testFactory): bool {
return $testFactory->only;
});
return array_filter($this->state, fn ($testFactory): bool => $testFactory->only);
}
/**
@ -147,8 +141,8 @@ final class TestRepository
foreach ($paths as $path) {
if (array_key_exists($path, $this->uses)) {
$this->uses[$path] = [
array_merge($this->uses[$path][0], $classOrTraits),
array_merge($this->uses[$path][1], $groups),
[...$this->uses[$path][0], ...$classOrTraits],
[...$this->uses[$path][1], ...$groups],
$this->uses[$path][2] + $hooks, // NOTE: array_merge will destroy numeric indices
];
} else {