chore: different refactors

This commit is contained in:
Nuno Maduro
2023-02-11 16:07:30 +00:00
parent e1406554fc
commit 8eaf4859ff
19 changed files with 207 additions and 165 deletions

View File

@ -54,22 +54,22 @@ final class TestRepository
*/
public function getFilenames(): array
{
$testCases = array_filter($this->testCases, static fn(TestCaseFactory $testCase): bool => $testCase->methodsUsingOnly() !== []);
$testCases = array_filter($this->testCases, static fn (TestCaseFactory $testCase): bool => $testCase->methodsUsingOnly() !== []);
if ($testCases === []) {
$testCases = $this->testCases;
}
return array_values(array_map(static fn(TestCaseFactory $factory): string => $factory->filename, $testCases));
return array_values(array_map(static fn (TestCaseFactory $factory): string => $factory->filename, $testCases));
}
/**
* Uses the given `$testCaseClass` on the given `$paths`.
*
* @param array<int, string> $classOrTraits
* @param array<int, string> $groups
* @param array<int, string> $paths
* @param array<int, Closure> $hooks
* @param array<int, string> $classOrTraits
* @param array<int, string> $groups
* @param array<int, string> $paths
* @param array<int, Closure> $hooks
*/
public function use(array $classOrTraits, array $groups, array $paths, array $hooks): void
{
@ -126,18 +126,18 @@ final class TestRepository
public function set(TestCaseMethodFactory $method): void
{
foreach ($this->testCaseFilters as $filter) {
if (!$filter->accept($method->filename)) {
if (! $filter->accept($method->filename)) {
return;
}
}
foreach ($this->testCaseMethodFilters as $filter) {
if (!$filter->accept($method)) {
if (! $filter->accept($method)) {
return;
}
}
if (!array_key_exists($method->filename, $this->testCases)) {
if (! array_key_exists($method->filename, $this->testCases)) {
$this->testCases[$method->filename] = new TestCaseFactory($method->filename);
}
@ -149,12 +149,12 @@ final class TestRepository
*/
public function makeIfNeeded(string $filename): void
{
if (!array_key_exists($filename, $this->testCases)) {
if (! array_key_exists($filename, $this->testCases)) {
return;
}
foreach ($this->testCaseFilters as $filter) {
if (!$filter->accept($filename)) {
if (! $filter->accept($filename)) {
return;
}
}
@ -167,12 +167,12 @@ final class TestRepository
*/
private function make(TestCaseFactory $testCase): void
{
$startsWith = static fn(string $target, string $directory): bool => Str::startsWith($target, $directory . DIRECTORY_SEPARATOR);
$startsWith = static fn (string $target, string $directory): bool => Str::startsWith($target, $directory.DIRECTORY_SEPARATOR);
foreach ($this->uses as $path => $uses) {
[$classOrTraits, $groups, $hooks] = $uses;
if ((!is_dir($path) && $testCase->filename === $path) || (is_dir($path) && $startsWith($testCase->filename, $path))) {
if ((! is_dir($path) && $testCase->filename === $path) || (is_dir($path) && $startsWith($testCase->filename, $path))) {
foreach ($classOrTraits as $class) {
/** @var string $class */
if (class_exists($class)) {