8000 minor #14746 [Config] Improved duplicated code in FileLocator (dosten) · symfony/symfony@662e281 · GitHub
[go: up one dir, main page]

Skip to content

Commit 662e281

Browse files
committed
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
2 parents 5c7cb56 + 30aa4e9 commit 662e281

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/Symfony/Component/Config/FileLocator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ public function locate($name, $currentPath = null, $first = true)
4747
return $name;
4848
}
4949

50-
$filepaths = array();
51-
if (null !== $currentPath && file_exists($file = $currentPath.DIRECTORY_SEPARATOR.$name)) {
52-
if (true === $first) {
53-
return $file;
54-
}
55-
$filepaths[] = $file;
50+
$paths = $this->paths;
51+
52+
if (null !== $currentPath) {
53+
array_unshift($paths, $currentPath);
5654
}
5755

58-
foreach ($this->paths as $path) {
56+
$filepaths = array();
57+
58+
foreach ($paths as $path) {
5959
if (file_exists($file = $path.DIRECTORY_SEPARATOR.$name)) {
6060
if (true === $first) {
6161
return $file;
@@ -65,7 +65,7 @@ public function locate($name, $currentPath = null, $first = true)
6565
}
6666

6767
if (!$filepaths) {
68-
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s%s).', $name, null !== $currentPath ? $currentPath.', ' : '', implode(', ', $this->paths)));
68+
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths)));
6969
}
7070

7171
return array_values(array_unique($filepaths));

0 commit comments

Comments
 (0)
0