Passed
Push — master ( d09870...716959 )
by Luis
02:38
created

CodeFinder::addDirectory()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 2
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP version 7.1
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 Symfony\Component\Finder\Finder;
11
12
/**
13
 * It inspects a directory finding all the files with PHP code and saves their contents
14
 *
15
 * The directory can be inspected recursively or not.
16
 * The contents of the files are used by the `TokenParser` to build the `RawDefinitions`
17
 */
18
class CodeFinder
19
{
20
    /** @var Finder */
21
    private $finder;
22
23
    /** @var string[] */
24
    private $files;
25
26 48
    public function __construct(Finder $finder = null)
27
    {
28 48
        $this->finder = $finder ?? new Finder();
29 48
        $this->files = [];
30 48
    }
31
32 36
    public function addDirectory(string $directory, bool $recursive = true): void
33
    {
34 36
        if (!$recursive) {
35 18
            $this->finder->depth(0);
36
        }
37 36
        $this->finder->in($directory)->files()->name('*.php');
38 36
        foreach ($this->finder as $file) {
39 33
            $this->files[] = $file->getContents();
40
        }
41 36
    }
42
43
    /** @return string[] */
44 36
    public function files(): array
45
    {
46 36
        return $this->files;
47
    }
48
}
49