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

CodeFinder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A files() 0 3 1
A addDirectory() 0 8 3
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