Completed
Push — develop ( 2993ce...48a3ec )
by Mike
09:32
created

Infrastructure/Parser/FlySystemCollector.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor\Infrastructure\Parser;
17
18
use phpDocumentor\Dsn;
19
use phpDocumentor\Parser\FileCollector;
20
use phpDocumentor\Infrastructure\FlySystemFactory;
21
use phpDocumentor\Infrastructure\SpecificationFactory;
0 ignored issues
show
This use statement conflicts with another class in this namespace, phpDocumentor\Infrastruc...er\SpecificationFactory.

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...
22
23
final class FlySystemCollector implements FileCollector
24
{
25
    /**
26
     * @var SpecificationFactory
27
     */
28
    private $specificationFactory;
29
30
    /**
31
     * @var FlySystemFactory
32
     */
33
    private $flySystemFactory;
34
35
    /**
36
     * FlySystemCollector constructor.
37
     */
38
    public function __construct(SpecificationFactory $specificationFactory, FlySystemFactory $flySystemFactory)
39
    {
40
        $this->specificationFactory = $specificationFactory;
41
        $this->flySystemFactory = $flySystemFactory;
42
    }
43
44 1
    public function getFiles(Dsn $dsn, array $paths, array $ignore, array $extensions): array
45
    {
46 1
        $specs = $this->specificationFactory->create($paths, $ignore, $extensions);
47
48 1
        $fileSystem = $this->flySystemFactory->create($dsn);
49
50 1
        $files = [];
51
52 1
        foreach ($fileSystem->find($specs) as $file) {
0 ignored issues
show
The method find() does not seem to exist on object<League\Flysystem\FilesystemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53 1
            $files[] = new FlySystemFile($fileSystem, $file['path']);
54
        }
55
56 1
        return $files;
57
    }
58
}
59