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;
|
||||
}
|
||||
|
||||
$filepaths = array();
|
||||
if (null !== $currentPath && file_exists($file = $currentPath.DIRECTORY_SEPARATOR.$name)) {
|
||||
if (true === $first) {
|
||||
return $file;
|
||||
}
|
||||
$filepaths[] = $file;
|
||||
$paths = $this->paths;
|
||||
|
||||
if (null !== $currentPath) {
|
||||
array_unshift($paths, $currentPath);
|
||||
}
|
||||
|
||||
foreach ($this->paths as $path) {
|
||||
$filepaths = array();
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($file = $path.DIRECTORY_SEPARATOR.$name)) {
|
||||
if (true === $first) {
|
||||
return $file;
|
||||
|
@ -65,7 +65,7 @@ class FileLocator implements FileLocatorInterface
|
|||
}
|
||||
|
||||
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));
|
||||
|
|
Reference in New Issue