remove hardcoded string

This commit is contained in:
Fabio Ivona
2022-09-22 10:58:12 +02:00
parent cbd4cefc1a
commit 98b04632ce

View File

@ -136,43 +136,6 @@ final class DatasetsRepository
return $namedData;
}
/**
* @return Closure|iterable<int|string, mixed>
*/
private static function getScopedDataset(string $name, string $currentTestFile)
{
$matchingDatasets = array_filter(self::$datasets, function (string $key) use ($name, $currentTestFile) {
[$datasetScope, $datasetName] = explode(self::SEPARATOR, $key);
if ($name !== $datasetName) {
return false;
}
if (! str_starts_with($currentTestFile, $datasetScope)) {
return false;
}
return true;
}, ARRAY_FILTER_USE_KEY);
$closestScopeDatasetKey = array_reduce(
array_keys($matchingDatasets),
fn ($keyA, $keyB) => $keyA !== null && strlen($keyA) > strlen($keyB) ? $keyA : $keyB
);
if ($keyA === null) {
return $keyB;
}
return strlen($keyA) > strlen($keyB) ? $keyA : $keyB;
});
if ($closestScopeDatasetKey === null) {
throw new DatasetDoesNotExist($name);
}
return $matchingDatasets[$closestScopeDatasetKey];
}
/**
* @param array<Closure|iterable<int|string, mixed>|string> $datasets
* @return array<array<mixed>>
@ -211,6 +174,37 @@ final class DatasetsRepository
return $processedDatasets;
}
/**
* @return Closure|iterable<int|string, mixed>
*/
private static function getScopedDataset(string $name, string $currentTestFile)
{
$matchingDatasets = array_filter(self::$datasets, function (string $key) use ($name, $currentTestFile) {
[$datasetScope, $datasetName] = explode(self::SEPARATOR, $key);
if ($name !== $datasetName) {
return false;
}
if (! str_starts_with($currentTestFile, $datasetScope)) {
return false;
}
return true;
}, ARRAY_FILTER_USE_KEY);
$closestScopeDatasetKey = array_reduce(
array_keys($matchingDatasets),
fn ($keyA, $keyB) => $keyA !== null && strlen($keyA) > strlen($keyB) ? $keyA : $keyB
);
if ($closestScopeDatasetKey === null) {
throw new DatasetDoesNotExist($name);
}
return $matchingDatasets[$closestScopeDatasetKey];
}
/**
* @param array<array<mixed>> $combinations
* @return array<array<array<mixed>>>