Passed
Push — union-types ( cd7236...b93e9c )
by Luis
10:52
created

SourceCodeFinder::fromConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.0
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
    public static function fromConfiguration(CodeFinderConfiguration $configuration): SourceCodeFinder
24
    {
25
        $finder = new Finder();
26
        if (! $configuration->recursive()) {
27
            $finder->depth(0);
28
        }
29
        return new self($finder);
30
    }
31
32
    private function __construct(private Finder $finder)
33
    {
34
    }
35
36
    public function find(CodebaseDirectory $directory): SourceCode
37
    {
38
        $sourceCode = new SourceCode();
39
        $this->finder->in($directory->absolutePath())->files()->name('*.php')->sortByName();
40
        foreach ($this->finder as $file) {
41
            $sourceCode->add($file->getContents());
42
        }
43
        return $sourceCode;
44
    }
45
}
46