Failed Conditions
Pull Request — master (#162)
by
unknown
05:20
created

Options::setAutoloaderPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace ComposerRequireChecker\Cli;
4
5
class Options
6
{
7
    private $symbolWhitelist = [
8
        'null',
9
        'true',
10
        'false', // consts
11
        'static',
12
        'self',
13
        'parent', // class hierarchy
14
        'array',
15
        'string',
16
        'int',
17
        'float',
18
        'bool',
19
        'iterable',
20
        'callable',
21
        'void',
22
        'object' // types
23
    ];
24
25
    private $phpCoreExtensions = [
26
        "Core",
27
        "date",
28
        "pcre",
29
        "Phar",
30
        "Reflection",
31
        "SPL",
32
        "standard",
33
    ];
34
35
    /**
36
     * @var string[] a list of glob patterns for files that should be scanned in addition
37
     * @see https://github.com/webmozart/glob
38
     */
39
    private $scanFiles = [];
40
41
    /**
42
     * @var string|null
43
     */
44
    private $autoloaderPath = null;
45
46 11
    public function __construct(array $options = [])
47
    {
48 11
        foreach ($options as $key => $option) {
49 9
            $methodName = 'set' . $this->getCamelCase($key);
50 9
            if (!method_exists($this, $methodName)) {
51 1
                throw new \InvalidArgumentException(
52 1
                    $key . ' is not a known option - there is no method ' . $methodName
53
                );
54
            }
55 8
            $this->$methodName($option);
56
        }
57 10
    }
58
59
    /**
60
     * @return array
61
     */
62 4
    public function getSymbolWhitelist(): array
63
    {
64 4
        return $this->symbolWhitelist;
65
    }
66
67
    /**
68
     * @return string[]
69
     */
70 8
    public function getPhpCoreExtensions(): array
71
    {
72 8
        return $this->phpCoreExtensions;
73
    }
74
75
    /**
76
     * @param array $symbolWhitelist
77
     */
78 2
    public function setSymbolWhitelist(array $symbolWhitelist)
79
    {
80 2
        $this->symbolWhitelist = $symbolWhitelist;
81 2
    }
82
83
    /**
84
     * @param array $phpCoreExtensions
85
     */
86 3
    public function setPhpCoreExtensions(array $phpCoreExtensions)
87
    {
88 3
        $this->phpCoreExtensions = $phpCoreExtensions;
89 3
    }
90
91
    /**
92
     * @return string[] a list of glob patterns for files that should be scanned in addition
93
     */
94 3
    public function getScanFiles(): array
95
    {
96 3
        return $this->scanFiles;
97
    }
98
99
    /**
100
     * @param string[] $scanFiles a list of glob patterns for files that should be scanned in addition
101
     */
102 2
    public function setScanFiles(array $scanFiles): void
103
    {
104 2
        $this->scanFiles = $scanFiles;
105 2
    }
106
107
    /**
108
     * @param string|null $autoloaderPath the path to Composer's autoload.php file
109
     */
110 8
    public function setAutoloaderPath(?string $autoloaderPath): void
111
    {
112 8
        $this->autoloaderPath = $autoloaderPath;
113 8
    }
114
115
    /**
116
     * @return string|null the path to Composer's autoload.php file
117
     */
118 7
    public function getAutoloaderPath(): ?string
119
    {
120 7
        return $this->autoloaderPath;
121
    }
122
123
    /**
124
     * @param string $string some-string
125
     * @return string someString
126
     */
127 9
    private function getCamelCase(string $string): string
128
    {
129 9
        return ucfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $string))));
130
    }
131
}
132