Completed
Pull Request — master (#448)
by
unknown
08:31
created

CliInput::__construct()   B

Complexity

Conditions 6
Paths 18

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 18
nop 3
dl 0
loc 25
rs 8.8977
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Phpmetrix\Console;
4
5
final class CliInput
6
{
7
8
    /** @var string[] */
9
    private $dirs;
10
11
    /** @var string[] */
12
    private $excludePaths;
13
14
    /**
15
     * File extensions
16
     *
17
     * @var string[]
18
     */
19
    private $exts;
20
21
    /**
22
     * @param string[] $dirs
23
     */
24
    public function __construct(array $dirs, ?string $exclude = null, ?string $ext = null)
25
    {
26
        $this->dirs = $dirs;
27
        $this->excludePaths = [];
28
29
        $paths = explode(',', $exclude ?? '');
30
        foreach ($paths as $item) {
31
            if (trim($item) === '') {
32
                continue;
33
            }
34
            $this->excludePaths[] = trim($item);
35
        }
36
37
        $exts = explode(',', $ext ?? '');
38
        foreach ($exts as $item) {
39
            if (trim($item) === '') {
40
                continue;
41
            }
42
            $this->exts[] = '*.' . ltrim(trim($item), '*.');
43
        }
44
45
        if (empty($this->exts)) {
46
            $this->exts = ['*.php'];
47
        }
48
    }
49
50
    /** @return string[] */
51
    public function directories() : array
52
    {
53
        return $this->dirs;
54
    }
55
56
    /** @return string[] */
57
    public function excludePaths() : array
58
    {
59
        return $this->excludePaths;
60
    }
61
62
    /** @return string[] */
63
    public function filenames() : array
64
    {
65
        return $this->exts;
66
    }
67
}
68