This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @author Patsura Dmitry https://github.com/ovr <[email protected]> |
||
4 | */ |
||
5 | |||
6 | namespace PHPSA; |
||
7 | |||
8 | use PhpParser\ParserFactory; |
||
9 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
||
10 | use Symfony\Component\Config\Definition\ConfigurationInterface; |
||
11 | use Symfony\Component\Config\Definition\Processor; |
||
12 | |||
13 | /** |
||
14 | * PHPSA configuration |
||
15 | */ |
||
16 | class Configuration implements ConfigurationInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $configuration; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $path; |
||
27 | |||
28 | /** |
||
29 | * Create a configuration from array. |
||
30 | * |
||
31 | * @param array $configuration |
||
32 | * @param array $analyzersConfiguration |
||
33 | */ |
||
34 | 1 | public function __construct(array $configuration = [], array $analyzersConfiguration = [], $path = "") |
|
0 ignored issues
–
show
|
|||
35 | { |
||
36 | 1 | $this->path = $path; |
|
37 | |||
38 | 1 | $processor = new Processor(); |
|
39 | |||
40 | 1 | $configTree = $this->getConfigTreeBuilder($analyzersConfiguration); |
|
41 | |||
42 | 1 | $this->configuration = $processor->process( |
|
43 | 1 | $configTree->buildTree(), |
|
44 | 1 | $configuration |
|
45 | ); |
||
46 | 1 | } |
|
47 | |||
48 | /** |
||
49 | * Generates the configuration tree. |
||
50 | * |
||
51 | * @param array $analyzersConfiguration |
||
52 | * |
||
53 | * @return TreeBuilder |
||
54 | */ |
||
55 | 1 | public function getConfigTreeBuilder(array $analyzersConfiguration = []) |
|
0 ignored issues
–
show
|
|||
56 | { |
||
57 | 1 | $treeBuilder = new TreeBuilder(); |
|
58 | 1 | $root = $treeBuilder->root('phpsa'); |
|
59 | |||
60 | $root |
||
61 | 1 | ->children() |
|
62 | 1 | ->booleanNode('blame')->defaultFalse()->end() |
|
63 | 1 | ->scalarNode('language_level') |
|
64 | 1 | ->defaultValue(PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION) |
|
65 | 1 | ->attribute('example', '5.3') |
|
66 | 1 | ->attribute('info', 'Will be used to automatically disable the analyzers that require a greater version of PHP.') |
|
67 | 1 | ->end() |
|
68 | 1 | ->enumNode('parser') |
|
69 | 1 | ->defaultValue('prefer-7') |
|
70 | 1 | ->attribute('label', 'Check types of Arguments.') |
|
71 | 1 | ->values([ |
|
72 | 1 | ParserFactory::PREFER_PHP7 => 'prefer-7', |
|
73 | 1 | ParserFactory::PREFER_PHP5 => 'prefer-5', |
|
74 | 1 | ParserFactory::ONLY_PHP7 => 'only-7', |
|
75 | 1 | ParserFactory::ONLY_PHP5 => 'only-5' |
|
76 | ]) |
||
77 | 1 | ->end() |
|
78 | 1 | ->end() |
|
79 | ; |
||
80 | |||
81 | $ignoredFilesAndDirs = $root |
||
0 ignored issues
–
show
$ignoredFilesAndDirs is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
82 | 1 | ->children() |
|
83 | 1 | ->arrayNode('ignore') |
|
84 | 1 | ->scalarPrototype()->end() |
|
85 | 1 | ->defaultValue(['/vendor']) |
|
86 | 1 | ->end(); |
|
87 | |||
88 | $analyzersConfigRoot = $root |
||
89 | 1 | ->children() |
|
90 | 1 | ->arrayNode('analyzers') |
|
91 | 1 | ->addDefaultsIfNotSet(); |
|
92 | |||
93 | 1 | $language_error = (new TreeBuilder())->root('language_error') |
|
94 | 1 | ->info("Contains all compiler notices. Those are raised when PHP with strict error reporting would create at least a Notice message. (mostly experimental)") |
|
95 | 1 | ->canBeDisabled(); |
|
96 | |||
97 | 1 | $analyzersConfigRoot->append($language_error); |
|
98 | |||
99 | 1 | foreach ($analyzersConfiguration as $config) { |
|
100 | 1 | $analyzersConfigRoot->append($config); |
|
101 | } |
||
102 | |||
103 | 1 | return $treeBuilder; |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * Sets a configuration setting. |
||
108 | * |
||
109 | * @param string $key |
||
110 | * @param mixed $value |
||
111 | */ |
||
112 | 1 | public function setValue($key, $value) |
|
113 | { |
||
114 | 1 | $this->configuration[$key] = $value; |
|
115 | 1 | } |
|
116 | |||
117 | /** |
||
118 | * Gets a configuration setting. |
||
119 | * |
||
120 | * @param string $key |
||
121 | * @param mixed $default |
||
122 | * |
||
123 | * @return mixed |
||
124 | */ |
||
125 | 1 | public function getValue($key, $default = null) |
|
126 | { |
||
127 | 1 | if (array_key_exists($key, $this->configuration)) { |
|
128 | 1 | return $this->configuration[$key]; |
|
129 | } |
||
130 | |||
131 | return $default; |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Checks if a configuration setting is set. |
||
136 | * |
||
137 | * @param string $key |
||
138 | * @return bool |
||
139 | */ |
||
140 | public function valueIsTrue($key) |
||
141 | { |
||
142 | return (bool) $this->configuration[$key]; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @return string |
||
147 | */ |
||
148 | public function getPath() |
||
149 | { |
||
150 | return $this->path; |
||
151 | } |
||
152 | } |
||
153 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.