Conditions | 4 |
Paths | 5 |
Total Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
7 | 102 | public function get(string $path) |
|
8 | { |
||
9 | 102 | if ($path == '.') { |
|
10 | 98 | return $this; |
|
11 | } |
||
12 | |||
13 | 100 | $attributes = explode('.', $path); |
|
14 | 100 | unset($attributes[0]); |
|
15 | |||
16 | 100 | $attribute = array_shift($attributes); |
|
17 | |||
18 | /** |
||
19 | * This condition is needed because a child could have the same name than a MutationTypeConfig attribute |
||
20 | * (type, linksTo, children). |
||
21 | */ |
||
22 | 100 | $value = $this->hasChild($attribute) ? $this->children[$attribute] : $this->{$attribute}; |
|
23 | |||
24 | 100 | if (!empty($attributes)) { |
|
25 | 74 | $value = $value->get('.' . implode('.', $attributes)); |
|
26 | } |
||
27 | |||
28 | 100 | return $value; |
|
29 | } |
||
30 | } |
||
31 |
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: