Passed
Push — stable ( 4bc356...4bd7f3 )
by Nuno
04:37 queued 02:22
created

src/Bootstrap/BaseLoadConfiguration.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Bootstrap;
15
16
use function ksort;
17
use function basename;
18
use Symfony\Component\Finder\Finder;
19
use Illuminate\Foundation\Bootstrap\LoadConfiguration;
0 ignored issues
show
This use statement conflicts with another class in this namespace, LaravelZero\Framework\Bootstrap\LoadConfiguration. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
20
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
21
22
/**
23
 * @internal
24
 */
25
final class BaseLoadConfiguration extends LoadConfiguration
26
{
27
    /**
28
     * Get all of the configuration files for the application.
29
     */
30 31
    protected function getConfigurationFiles(ApplicationContract $app): array
31
    {
32 31
        $files = [];
33
34 31
        $configPath = $app->configPath();
35
36 31
        $configFiles = Finder::create()
37 31
            ->files()
38 31
            ->name('*.php')
39 31
            ->in($configPath);
40
41 31
        foreach ($configFiles as $file) {
42 31
            $directory = $this->getNestedDirectory($file, $configPath);
43 31
            $files[$directory.basename($file->getPathname(), '.php')] = $file->getPathname();
44
        }
45
46 31
        ksort($files, SORT_NATURAL);
47
48 31
        return $files;
49
    }
50
}
51