@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use ArrayIterator, ArrayObject, RecursiveArrayIterator, RecursiveIteratorIterator, Traversable; |
16 | 16 | |
17 | -trait SearchableArray{ |
|
17 | +trait SearchableArray { |
|
18 | 18 | use DotArray; |
19 | 19 | |
20 | 20 | /** |
@@ -32,22 +32,22 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @param array|object|\Traversable|\ArrayIterator|\ArrayObject|null $array |
34 | 34 | */ |
35 | - public function __construct($array = null){ |
|
35 | + public function __construct($array = null) { |
|
36 | 36 | |
37 | - if(($array instanceof ArrayObject) || ($array instanceof ArrayIterator)){ |
|
37 | + if (($array instanceof ArrayObject) || ($array instanceof ArrayIterator)) { |
|
38 | 38 | $this->array = $array->getArrayCopy(); |
39 | 39 | } |
40 | - elseif($array instanceof Traversable){ |
|
40 | + elseif ($array instanceof Traversable) { |
|
41 | 41 | $this->array = iterator_to_array($array); |
42 | 42 | } |
43 | 43 | // yields unexpected results with DotArray |
44 | - elseif(gettype($array) === 'object'){ |
|
44 | + elseif (gettype($array) === 'object') { |
|
45 | 45 | $this->array = get_object_vars($array); |
46 | 46 | } |
47 | - elseif(is_array($array)){ |
|
47 | + elseif (is_array($array)) { |
|
48 | 48 | $this->array = $array; |
49 | 49 | } |
50 | - else{ |
|
50 | + else { |
|
51 | 51 | $this->array = []; |
52 | 52 | } |
53 | 53 | } |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return mixed |
59 | 59 | */ |
60 | - public function search(string $dotKey){ |
|
60 | + public function search(string $dotKey) { |
|
61 | 61 | $this->iterator = $this->getRecursiveIteratorIterator(); |
62 | 62 | |
63 | - foreach($this->iterator as $v){ |
|
63 | + foreach ($this->iterator as $v) { |
|
64 | 64 | |
65 | - if($this->getPath() === $dotKey){ |
|
65 | + if ($this->getPath() === $dotKey) { |
|
66 | 66 | return $v; |
67 | 67 | } |
68 | 68 | |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | public function isset(string $dotKey):bool{ |
80 | 80 | $this->iterator = $this->getRecursiveIteratorIterator(); |
81 | 81 | |
82 | - foreach($this->iterator as $v){ |
|
82 | + foreach ($this->iterator as $v) { |
|
83 | 83 | |
84 | - if($this->getPath() === $dotKey){ |
|
84 | + if ($this->getPath() === $dotKey) { |
|
85 | 85 | return true; |
86 | 86 | } |
87 | 87 |
@@ -36,18 +36,15 @@ |
||
36 | 36 | |
37 | 37 | if(($array instanceof ArrayObject) || ($array instanceof ArrayIterator)){ |
38 | 38 | $this->array = $array->getArrayCopy(); |
39 | - } |
|
40 | - elseif($array instanceof Traversable){ |
|
39 | + } elseif($array instanceof Traversable){ |
|
41 | 40 | $this->array = iterator_to_array($array); |
42 | 41 | } |
43 | 42 | // yields unexpected results with DotArray |
44 | 43 | elseif(gettype($array) === 'object'){ |
45 | 44 | $this->array = get_object_vars($array); |
46 | - } |
|
47 | - elseif(is_array($array)){ |
|
45 | + } elseif(is_array($array)){ |
|
48 | 46 | $this->array = $array; |
49 | - } |
|
50 | - else{ |
|
47 | + } else{ |
|
51 | 48 | $this->array = []; |
52 | 49 | } |
53 | 50 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @link https://github.com/laravel/framework/blob/5.4/src/Illuminate/Support/Arr.php |
17 | 17 | */ |
18 | -trait DotArray{ |
|
18 | +trait DotArray { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var array |
@@ -30,17 +30,17 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return mixed returns $array[$key], $default otherwise. |
32 | 32 | */ |
33 | - public function get(string $dotKey, $default = null){ |
|
33 | + public function get(string $dotKey, $default = null) { |
|
34 | 34 | |
35 | - if(isset($this->array[$dotKey])){ |
|
35 | + if (isset($this->array[$dotKey])) { |
|
36 | 36 | return $this->array[$dotKey]; |
37 | 37 | } |
38 | 38 | |
39 | 39 | $array = &$this->array; |
40 | 40 | |
41 | - foreach(explode('.', $dotKey) as $segment){ |
|
41 | + foreach (explode('.', $dotKey) as $segment) { |
|
42 | 42 | |
43 | - if(!is_array($array) || !array_key_exists($segment, $array)){ |
|
43 | + if (!is_array($array) || !array_key_exists($segment, $array)) { |
|
44 | 44 | return $default; |
45 | 45 | } |
46 | 46 | |
@@ -59,19 +59,19 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function in(string $dotKey):bool{ |
61 | 61 | |
62 | - if(empty($this->array)){ |
|
62 | + if (empty($this->array)) { |
|
63 | 63 | return false; |
64 | 64 | } |
65 | 65 | |
66 | - if(array_key_exists($dotKey, $this->array)){ |
|
66 | + if (array_key_exists($dotKey, $this->array)) { |
|
67 | 67 | return true; |
68 | 68 | } |
69 | 69 | |
70 | 70 | $array = &$this->array; |
71 | 71 | |
72 | - foreach(explode('.', $dotKey) as $segment){ |
|
72 | + foreach (explode('.', $dotKey) as $segment) { |
|
73 | 73 | |
74 | - if(!is_array($array) || !array_key_exists($segment, $array)){ |
|
74 | + if (!is_array($array) || !array_key_exists($segment, $array)) { |
|
75 | 75 | return false; |
76 | 76 | } |
77 | 77 | |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return \chillerlan\Traits\ArrayHelpers\DotArray |
93 | 93 | */ |
94 | - public function set(string $dotKey, $value){ |
|
94 | + public function set(string $dotKey, $value) { |
|
95 | 95 | |
96 | - if(empty($dotKey)){ |
|
96 | + if (empty($dotKey)) { |
|
97 | 97 | $this->array = $value; |
98 | 98 | |
99 | 99 | return $this; |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | $array = &$this->array; |
103 | 103 | $keys = explode('.', $dotKey); |
104 | 104 | |
105 | - while(count($keys) > 1){ |
|
105 | + while (count($keys) > 1) { |
|
106 | 106 | $dotKey = array_shift($keys); |
107 | 107 | |
108 | 108 | // If the key doesn't exist at this depth, we will just create an empty array |
109 | 109 | // to hold the next value, allowing us to create the arrays to hold final |
110 | 110 | // values at the correct depth. Then we'll keep digging into the array. |
111 | - if(!isset($array[$dotKey]) || !is_array($array[$dotKey])){ |
|
111 | + if (!isset($array[$dotKey]) || !is_array($array[$dotKey])) { |
|
112 | 112 | $array[$dotKey] = []; |
113 | 113 | } |
114 | 114 |