function RelativePathCalculator::parts
@psalm-param non-empty-string $filename
@psalm-return list<non-empty-string>
1 call to RelativePathCalculator::parts()
- RelativePathCalculator::calculate in vendor/
phpunit/ phpunit/ src/ Runner/ Baseline/ RelativePathCalculator.php - @psalm-param non-empty-string $filename
File
-
vendor/
phpunit/ phpunit/ src/ Runner/ Baseline/ RelativePathCalculator.php, line 65
Class
- RelativePathCalculator
- @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Namespace
PHPUnit\Runner\BaselineCode
public function parts(string $filename) : array {
$schemePosition = strpos($filename, '://');
if ($schemePosition !== false) {
$filename = substr($filename, $schemePosition + 3);
assert($filename !== '');
}
$parentParts = explode('/', trim(str_replace('\\', '/', $this->baselineDirectory), '/'));
$parentPartsCount = count($parentParts);
$filenameParts = explode('/', trim(str_replace('\\', '/', $filename), '/'));
$filenamePartsCount = count($filenameParts);
$i = 0;
for (; $i < $filenamePartsCount; $i++) {
if ($parentPartsCount < $i + 1) {
break;
}
$parentPath = implode('/', array_slice($parentParts, 0, $i + 1));
$filenamePath = implode('/', array_slice($filenameParts, 0, $i + 1));
if ($parentPath !== $filenamePath) {
break;
}
}
if ($i === 0) {
return [
$filename,
];
}
$dotsCount = $parentPartsCount - $i;
assert($dotsCount >= 0);
return array_merge(array_fill(0, $dotsCount, '..'), array_slice($filenameParts, $i));
}