Improved duplicated code in FileLocator
This commit is contained in:
parent
cc749a67f6
commit
30aa4e96c6
@ -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