Passed
Push — master ( f58add...4aa999 )
by Luis
54s queued 13s
created

SourceCodeFinder::files()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 8
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 7.4
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Parser;
9
10
use PhUml\Parser\Code\PhpCodeParser;
11
use Symfony\Component\Finder\Finder;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Finder\Finder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
/**
14
 * It inspects a directory finding all the files with PHP code and saves their contents
15
 *
16
 * This finder inspect inner directories recursively.
17
 * The contents of the files are used by the `PhpParser` to build a `Codebase`
18
 *
19
 * @see PhpCodeParser::parse()
20
 */
21
final class SourceCodeFinder implements CodeFinder
22
{
23
    protected Finder $finder;
24
25
    private CodebaseDirectory $directory;
26
27
    public static function recursive(CodebaseDirectory $directory): SourceCodeFinder
28
    {
29
        return new self(new Finder(), $directory);
30
    }
31
32
    public static function nonRecursive(CodebaseDirectory $directory): SourceCodeFinder
33
    {
34
        $finder = new Finder();
35
        $finder->depth(0);
36
        return new self($finder, $directory);
37
    }
38
39
    private function __construct(Finder $finder, CodebaseDirectory $directory)
40
    {
41
        $this->finder = $finder;
42
        $this->directory = $directory;
43
    }
44
45
    /** @return string[] */
46
    public function files(): array
47
    {
48
        $files = [];
49
        $this->finder->in($this->directory->absolutePath())->files()->name('*.php')->sortByName();
50
        foreach ($this->finder as $file) {
51
            $files[] = $file->getContents();
52
        }
53
        return $files;
54
    }
55
}
56