Completed
Push — master ( dcd98f...8e1797 )
by Luis
07:11 queued 02:59
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
namespace PhUml\Parser;
8
9
use Symfony\Component\Finder\Finder;
10
11
class CodeFinder
12
{
13
    /** @var Finder */
14
    private $finder;
15
16
    /** @var string[] */
17
    private $files;
18
19 36
    public function __construct(Finder $finder = null)
20
    {
21 36
        $this->finder = $finder ?? new Finder();
22 36
        $this->files = [];
23 36
    }
24
25
26 12
    public function addDirectory(string $directory, bool $recursive = true): void
27
    {
28 12
        if (!$recursive) {
29 6
            $this->finder->depth(0);
30
        }
31 12
        $this->finder->in($directory)->files()->name('*.php');
32 12
        foreach ($this->finder as $file) {
33 12
            $this->files[] = $file->getContents();
34
        }
35 12
    }
36
37
    /** @return string[] */
38 15
    public function files(): array
39
    {
40 15
        return $this->files;
41
    }
42
}
43