minor #14746 [Config] Improved duplicated code in FileLocator (dosten)
This PR was merged into the 2.3 branch.
Discussion
----------
[Config] Improved duplicated code in FileLocator
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| License | MIT
This PR improves a duplicate check prepending the current path (if exists) to the list of paths.
Commits
-------
30aa4e9
Improved duplicated code in FileLocator
This commit is contained in:
commit
662e2816e3
@ -47,15 +47,15 @@ class FileLocator implements FileLocatorInterface
|
|||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filepaths = array();
|
$paths = $this->paths;
|
||||||
if (null !== $currentPath && file_exists($file = $currentPath.DIRECTORY_SEPARATOR.$name)) {
|
|
||||||
if (true === $first) {
|
if (null !== $currentPath) {
|
||||||
return $file;
|
array_unshift($paths, $currentPath);
|
||||||
}
|
|
||||||
$filepaths[] = $file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->paths as $path) {
|
$filepaths = array();
|
||||||
|
|
||||||
|
foreach ($paths as $path) {
|
||||||
if (file_exists($file = $path.DIRECTORY_SEPARATOR.$name)) {
|
if (file_exists($file = $path.DIRECTORY_SEPARATOR.$name)) {
|
||||||
if (true === $first) {
|
if (true === $first) {
|
||||||
return $file;
|
return $file;
|
||||||
@ -65,7 +65,7 @@ class FileLocator implements FileLocatorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$filepaths) {
|
if (!$filepaths) {
|
||||||
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s%s).', $name, null !== $currentPath ? $currentPath.', ' : '', implode(', ', $this->paths)));
|
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_values(array_unique($filepaths));
|
return array_values(array_unique($filepaths));
|
||||||
|
Reference in New Issue
Block a user