Options::getSymbolWhitelist()   A
last analyzed

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 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
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 13
    public function __construct(array $options = [])
43
    {
44 13
        foreach ($options as $key => $option) {
45 7
            $methodName = 'set' . $this->getCamelCase($key);
46 7
            if (!method_exists($this, $methodName)) {
47 1
                throw new \InvalidArgumentException(
48 1
                    $key . ' is not a known option - there is no method ' . $methodName
49
                );
50
            }
51 6
            $this->$methodName($option);
52
        }
53 12
    }
54
55
    /**
56
     * @return array
57
     */
58 8
    public function getSymbolWhitelist(): array
59
    {
60 8
        return $this->symbolWhitelist;
61
    }
62
63
    /**
64
     * @return string[]
65
     */
66 10
    public function getPhpCoreExtensions(): array
67
    {
68 10
        return $this->phpCoreExtensions;
69
    }
70
71
    /**
72
     * @param array $symbolWhitelist
73
     */
74 2
    public function setSymbolWhitelist(array $symbolWhitelist)
75
    {
76 2
        $this->symbolWhitelist = $symbolWhitelist;
77 2
    }
78
79
    /**
80
     * @param array $phpCoreExtensions
81
     */
82 3
    public function setPhpCoreExtensions(array $phpCoreExtensions)
83
    {
84 3
        $this->phpCoreExtensions = $phpCoreExtensions;
85 3
    }
86
87
    /**
88
     * @return string[] a list of glob patterns for files that should be scanned in addition
89
     */
90 8
    public function getScanFiles(): array
91
    {
92 8
        return $this->scanFiles;
93
    }
94
95
    /**
96
     * @param string[] $scanFiles a list of glob patterns for files that should be scanned in addition
97
     */
98 3
    public function setScanFiles(array $scanFiles): void
99
    {
100 3
        $this->scanFiles = $scanFiles;
101 3
    }
102
103
    /**
104
     * @param string $string some-string
105
     * @return string someString
106
     */
107 7
    private function getCamelCase(string $string): string
108
    {
109 7
        return ucfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $string))));
110
    }
111
}
112