ConfigurationReader::getConfigValue()   D
last analyzed

Complexity

Conditions 9
Paths 6

Size

Total Lines 28
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 9.0164

Importance

Changes 0
Metric Value
cc 9
eloc 14
nc 6
nop 0
dl 0
loc 28
ccs 16
cts 17
cp 0.9412
crap 9.0164
rs 4.909
c 0
b 0
f 0
1
<?php
2
3
namespace Anavel\Crud\Abstractor;
4
5
trait ConfigurationReader
6
{
7 20
    public function getConfigValue()
8
    {
9 20
        if (!property_exists($this, 'config') || !is_array($this->config) || empty($this->config)) {
0 ignored issues
show
Bug introduced by
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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 = [];
0 ignored issues
show
Unused Code introduced by
$nestedConfig 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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