Completed
Push — develop ( 0b8425...c51867 )
by Jaap
15s queued 11s
created

FlySystemCollector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 7
cts 11
cp 0.6364
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getFiles() 0 14 2
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\DomainModel\Dsn;
19
use phpDocumentor\DomainModel\Parser\FileCollector;
20
use phpDocumentor\Infrastructure\FlySystemFactory;
21
use phpDocumentor\Infrastructure\SpecificationFactory;
0 ignored issues
show
Bug introduced by Jaapio
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
Bug introduced by Jaapio
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