mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
Code quality improvements
This commit is contained in:
@ -61,11 +61,11 @@ final class DatasetsRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Closure|iterable<int|string, mixed>|never
|
||||
* @return Closure|array<int|string, mixed>|never
|
||||
*
|
||||
* @throws ShouldNotHappen
|
||||
*/
|
||||
public static function get(string $filename, string $description): Closure|iterable
|
||||
public static function get(string $filename, string $description)
|
||||
{
|
||||
$dataset = self::$withs[$filename.'>>>'.$description];
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ final class TempRepository
|
||||
/**
|
||||
* Creates a new Temp Repository instance.
|
||||
*/
|
||||
public function __construct(private string $filename)
|
||||
public function __construct(private readonly string $filename)
|
||||
{
|
||||
// ..
|
||||
}
|
||||
@ -24,10 +24,7 @@ final class TempRepository
|
||||
*/
|
||||
public function add(string $element): void
|
||||
{
|
||||
$this->save(array_merge(
|
||||
$this->all(),
|
||||
[$element]
|
||||
));
|
||||
$this->save([...$this->all(), ...[$element]]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +56,7 @@ final class TempRepository
|
||||
|
||||
assert(is_string($contents));
|
||||
|
||||
$all = json_decode($contents, true);
|
||||
$all = json_decode($contents, true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
return is_array($all) ? $all : [];
|
||||
}
|
||||
@ -71,7 +68,7 @@ final class TempRepository
|
||||
*/
|
||||
private function save(array $elements): void
|
||||
{
|
||||
$contents = json_encode($elements);
|
||||
$contents = json_encode($elements, JSON_THROW_ON_ERROR);
|
||||
|
||||
file_put_contents(self::FOLDER.'/'.$this->filename.'.json', $contents);
|
||||
}
|
||||
|
||||
@ -42,9 +42,9 @@ final class TestRepository
|
||||
*/
|
||||
public function getFilenames(): array
|
||||
{
|
||||
$testCases = array_filter($this->testCases, static fn (TestCaseFactory $testCase) => count($testCase->methodsUsingOnly()) > 0);
|
||||
$testCases = array_filter($this->testCases, static fn (TestCaseFactory $testCase) => $testCase->methodsUsingOnly() !== []);
|
||||
|
||||
if (count($testCases) === 0) {
|
||||
if ($testCases === []) {
|
||||
$testCases = $this->testCases;
|
||||
}
|
||||
|
||||
@ -62,9 +62,13 @@ final class TestRepository
|
||||
public function use(array $classOrTraits, array $groups, array $paths, array $hooks): void
|
||||
{
|
||||
foreach ($classOrTraits as $classOrTrait) {
|
||||
if (! class_exists($classOrTrait) && ! trait_exists($classOrTrait)) {
|
||||
throw new TestCaseClassOrTraitNotFound($classOrTrait);
|
||||
if (class_exists($classOrTrait)) {
|
||||
continue;
|
||||
}
|
||||
if (trait_exists($classOrTrait)) {
|
||||
continue;
|
||||
}
|
||||
throw new TestCaseClassOrTraitNotFound($classOrTrait);
|
||||
}
|
||||
|
||||
foreach ($paths as $path) {
|
||||
@ -137,7 +141,7 @@ final class TestRepository
|
||||
}
|
||||
|
||||
foreach ($testCase->methods as $method) {
|
||||
$method->groups = array_merge($groups, $method->groups);
|
||||
$method->groups = [...$groups, ...$method->groups];
|
||||
}
|
||||
|
||||
$testCase->factoryProxies->add($testCase->filename, 0, '__addBeforeAll', [$hooks[0] ?? null]);
|
||||
|
||||
Reference in New Issue
Block a user