chore: improves type coverage

This commit is contained in:
Nuno Maduro
2022-12-07 09:17:35 +00:00
parent c5f6923e5a
commit 70f447a8bc
22 changed files with 109 additions and 68 deletions

View File

@ -90,8 +90,7 @@ final class DatasetsRepository
*/
public static function resolve(array $dataset, string $currentTestFile): array|null
{
/* @phpstan-ignore-next-line */
if (empty($dataset)) {
if ($dataset === []) {
return null;
}
@ -177,25 +176,21 @@ final class DatasetsRepository
/**
* @return Closure|iterable<int|string, mixed>
*/
private static function getScopedDataset(string $name, string $currentTestFile)
private static function getScopedDataset(string $name, string $currentTestFile): Closure|iterable
{
$matchingDatasets = array_filter(self::$datasets, function (string $key) use ($name, $currentTestFile) {
$matchingDatasets = array_filter(self::$datasets, function (string $key) use ($name, $currentTestFile): bool {
[$datasetScope, $datasetName] = explode(self::SEPARATOR, $key);
if ($name !== $datasetName) {
return false;
}
if (! str_starts_with($currentTestFile, $datasetScope)) {
return false;
}
return true;
return str_starts_with($currentTestFile, $datasetScope);
}, ARRAY_FILTER_USE_KEY);
$closestScopeDatasetKey = array_reduce(
array_keys($matchingDatasets),
fn ($keyA, $keyB) => $keyA !== null && strlen($keyA) > strlen($keyB) ? $keyA : $keyB
fn ($keyA, $keyB) => $keyA !== null && strlen((string) $keyA) > strlen($keyB) ? $keyA : $keyB
);
if ($closestScopeDatasetKey === null) {

View File

@ -42,7 +42,7 @@ final class TestRepository
*/
public function getFilenames(): array
{
$testCases = array_filter($this->testCases, static fn (TestCaseFactory $testCase) => $testCase->methodsUsingOnly() !== []);
$testCases = array_filter($this->testCases, static fn (TestCaseFactory $testCase): bool => $testCase->methodsUsingOnly() !== []);
if ($testCases === []) {
$testCases = $this->testCases;