Conditions | 5 |
Paths | 5 |
Total Lines | 19 |
Code Lines | 10 |
Lines | 6 |
Ratio | 31.58 % |
Tests | 10 |
CRAP Score | 5.0187 |
Changes | 0 |
1 | <?php |
||
47 | 3 | public static function has(array $array, $key) |
|
48 | { |
||
49 | 3 | if (array_key_exists($key, $array)) { |
|
50 | 2 | return true; |
|
51 | } |
||
52 | |||
53 | 2 | if (strpos($key, '.') === false) { |
|
54 | 1 | return false; |
|
55 | } |
||
56 | |||
57 | 1 | $keys = explode('.', $key); |
|
58 | 1 | View Code Duplication | while (count($keys) > 0) { |
59 | 1 | $subSet = $array[array_shift($keys)]; |
|
60 | 1 | if (is_array($subSet)) { |
|
61 | 1 | return static::has($subSet, join('.', $keys)); |
|
62 | } |
||
63 | } |
||
64 | |||
65 | return false; |
||
66 | } |
||
68 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.