FileHandler::addFileSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Openl10n\Cli\File;
4
5
use Openl10n\Cli\ServiceContainer\Configuration\ConfigurationLoader;
6
7
/**
8
 * Handle the set of FileSet (patterns) defined by user in his config file
9
 */
10
class FileHandler
11
{
12
    /**
13
     * @var ConfigurationLoader
14
     */
15
    protected $configurationLoader;
16
17
    /**
18
     * @var FileSet[]
19
     */
20
    protected $fileSets;
21
22
    /**
23
     * @param ConfigurationLoader $configurationLoader
24
     * @param array $filesConfiguration
25
     */
26
    public function __construct(ConfigurationLoader $configurationLoader, array $filesConfiguration = array())
27
    {
28
        $this->configurationLoader = $configurationLoader;
29
        $this->fileSets = [];
30
31
        foreach ($filesConfiguration as $config) {
32
            $rootDir = $this->configurationLoader->getRootDirectory();
33
            $matcher = new Matcher($config['pattern']);
34
            $options = $config['options'];
35
            $fileSet = new FileSet($rootDir, $matcher, $options);
36
37
            $this->addFileSet($fileSet);
38
        }
39
    }
40
41
    /**
42
     * Add a FileSet to the list handle by this FileHandler
43
     *
44
     * @param FileSet $fileSet
45
     */
46
    public function addFileSet(FileSet $fileSet)
47
    {
48
        $this->fileSets[] = $fileSet;
49
    }
50
51
    /**
52
     * Retrieve FileSet list
53
     *
54
     * @return array|FileSet[]
55
     */
56
    public function getFileSets()
57
    {
58
        return $this->fileSets;
59
    }
60
}
61