Completed
Push — develop ( 1aa11f...71fd61 )
by Jaap
03:29
created

FlySystemCollector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
rs 9.4285
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 *  For the full copyright and license information, please view the LICENSE
6
 *  file that was distributed with this source code.
7
 *
8
 *  @copyright 2010-2017 Mike van Riel<[email protected]>
9
 *  @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 *  @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Infrastructure\Parser;
14
15
use phpDocumentor\DomainModel\Dsn;
16
use phpDocumentor\DomainModel\Parser\FileCollector;
17
use phpDocumentor\Infrastructure\FlySystemFactory;
18
use phpDocumentor\Infrastructure\SpecificationFactory;
0 ignored issues
show
Bug introduced by
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...
19
use phpDocumentor\Reflection\File;
20
21
final class FlySystemCollector implements FileCollector
22
{
23
    /**
24
     * @var SpecificationFactory
25
     */
26
    private $specificationFactory;
27
    /**
28
     * @var FlySystemFactory
29
     */
30
    private $flySystemFactory;
31
32
    /**
33
     * FlySystemCollector constructor.
34
     * @param SpecificationFactory $specificationFactory
35
     * @param FlySystemFactory $flySystemFactory
36
     */
37
    public function __construct(SpecificationFactory $specificationFactory, FlySystemFactory $flySystemFactory)
38
    {
39
        $this->specificationFactory = $specificationFactory;
40
        $this->flySystemFactory = $flySystemFactory;
41
    }
42
43
    public function getFiles(Dsn $dsn, array $paths, array $ignore, array $extensions): array
44
    {
45
        $specs = $this->specificationFactory->create($paths, $ignore, $extensions);
46
47
        $fileSystems = [];
48
49
        $fileSystems[] = $this->flySystemFactory->create($dsn);
50
51
        $files = [];
52
        foreach ($fileSystems as $fileSystem) {
53
            $result = $fileSystem->find($specs);
54
            foreach ($result as $file) {
55
                $files[] = new FlySystemFile($fileSystem, $file['path']);
56
            }
57
        }
58
59
        return $files;
60
    }
61
}
62