| Conditions | 9 |
| Paths | 6 |
| Total Lines | 28 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 9.0164 |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | 20 | public function getConfigValue() |
|
| 8 | { |
||
| 9 | 20 | if (!property_exists($this, 'config') || !is_array($this->config) || empty($this->config)) { |
|
|
|
|||
| 10 | return; |
||
| 11 | } |
||
| 12 | |||
| 13 | 20 | $params = func_get_args(); |
|
| 14 | |||
| 15 | 20 | $lastParam = array_pop($params); |
|
| 16 | |||
| 17 | 20 | $nestedConfig = $this->config; |
|
| 18 | |||
| 19 | 20 | if (is_array($params) && count($params) > 0) { |
|
| 20 | 18 | foreach ($params as $configKey) { |
|
| 21 | 18 | if (!array_key_exists($configKey, $nestedConfig)) { |
|
| 22 | 10 | $nestedConfig = []; |
|
| 23 | |||
| 24 | 10 | return; |
|
| 25 | } |
||
| 26 | |||
| 27 | 8 | $nestedConfig = $nestedConfig[$configKey]; |
|
| 28 | 8 | } |
|
| 29 | 8 | } |
|
| 30 | |||
| 31 | 20 | if (array_key_exists($lastParam, $nestedConfig)) { |
|
| 32 | 10 | return $nestedConfig[$lastParam]; |
|
| 33 | } |
||
| 34 | 10 | } |
|
| 35 | } |
||
| 36 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: