Completed
Pull Request — master (#77)
by Matthias
05:01
created

Options   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
eloc 39
dl 0
loc 101
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getScanFiles() 0 3 1
A getCamelCase() 0 3 1
A __construct() 0 10 3
A getPhpCoreExtensions() 0 3 1
A setPhpCoreExtensions() 0 3 1
A setScanFiles() 0 3 1
A getSymbolWhitelist() 0 3 1
A setSymbolWhitelist() 0 3 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
    private $scanFiles = [];
36 5
37
38 5
    public function __construct(array $options = [])
39 4
    {
40 4
        foreach ($options as $key => $option) {
41 1
            $methodName = 'set' . $this->getCamelCase($key);
42 1
            if (!method_exists($this, $methodName)) {
43
                throw new \InvalidArgumentException(
44
                    $key . ' is not a known option - there is no method ' . $methodName
45 3
                );
46
            }
47 4
            $this->$methodName($option);
48
        }
49
    }
50
51
    /**
52 2
     * @return array
53
     */
54 2
    public function getSymbolWhitelist(): array
55
    {
56
        return $this->symbolWhitelist;
57
    }
58
59
    /**
60 2
     * @return array
61
     */
62 2
    public function getPhpCoreExtensions(): array
63
    {
64
        return $this->phpCoreExtensions;
65
    }
66
67
    /**
68 2
     * @param array $symbolWhitelist
69
     */
70 2
    public function setSymbolWhitelist(array $symbolWhitelist)
71 2
    {
72
        $this->symbolWhitelist = $symbolWhitelist;
73
    }
74
75
    /**
76 2
     * @param array $phpCoreExtensions
77
     */
78 2
    public function setPhpCoreExtensions(array $phpCoreExtensions)
79 2
    {
80
        $this->phpCoreExtensions = $phpCoreExtensions;
81
    }
82
83
    /**
84
     * @return array
85 4
     */
86
    public function getScanFiles(): array
87 4
    {
88
        return $this->scanFiles;
89
    }
90
91
    /**
92
     * @param array $scanFiles
93
     */
94
    public function setScanFiles(array $scanFiles): void
95
    {
96
        $this->scanFiles = $scanFiles;
97
    }
98
99
    /**
100
     * @param string $string some-string
101
     * @return string someString
102
     */
103
    private function getCamelCase(string $string): string
104
    {
105
        return ucfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $string))));
106
    }
107
}
108