Conditions | 4 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | public function findConfig($templatePath, $key = null) |
||
22 | { |
||
23 | if (is_file($this->getConfigPath($templatePath)) === false) { |
||
24 | throw new \InvalidArgumentException( |
||
25 | sprintf('Template "%s" with key "%s" not found', $templatePath, $key) |
||
26 | ); |
||
27 | } |
||
28 | |||
29 | if ($key === null) { |
||
30 | return $config; |
||
|
|||
31 | } |
||
32 | |||
33 | $config = $this->loadConfig($templatePath); |
||
34 | |||
35 | if (isset($config[$key])) { |
||
36 | return $config[$key]; |
||
37 | } |
||
38 | |||
39 | throw new \InvalidArgumentException( |
||
40 | sprintf('Template "%s" with key "%s" not found', $templatePath, $key) |
||
41 | ); |
||
42 | } |
||
43 | |||
62 |
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
The above code is perfectly fine. Now imagine that we re-order the statements:
In that case,
$x
would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.