ConfigurationReader   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
D getConfigValue() 0 28 9
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