@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * a generic container with magic getter and setter |
| 19 | 19 | */ |
| 20 | -trait Container{ |
|
| 20 | +trait Container { |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * @var \chillerlan\Traits\DotEnv|null |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | * @param iterable $properties |
| 29 | 29 | * @param \chillerlan\Traits\DotEnv|null $env |
| 30 | 30 | */ |
| 31 | - public function __construct(array $properties = null, DotEnv $env = null){ |
|
| 31 | + public function __construct(array $properties = null, DotEnv $env = null) { |
|
| 32 | 32 | $this->env = $env; |
| 33 | 33 | |
| 34 | - if(!empty($properties)){ |
|
| 34 | + if (!empty($properties)) { |
|
| 35 | 35 | $this->__fromIterable($properties); |
| 36 | 36 | } |
| 37 | 37 | |
@@ -42,18 +42,18 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return mixed |
| 44 | 44 | */ |
| 45 | - public function __get(string $property){ |
|
| 45 | + public function __get(string $property) { |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | # if(method_exists($this, 'get_'.$property) && $this->__isset($property)){ |
| 49 | 49 | # return call_user_func([$this, 'get_'.$property]); |
| 50 | 50 | # } |
| 51 | 51 | |
| 52 | - if($this->__isset($property)){ |
|
| 52 | + if ($this->__isset($property)) { |
|
| 53 | 53 | return $this->{$property}; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if(property_exists($this, 'env') && $this->env instanceof DotEnv){ |
|
| 56 | + if (property_exists($this, 'env') && $this->env instanceof DotEnv) { |
|
| 57 | 57 | return $this->env->get($property); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return void |
| 68 | 68 | */ |
| 69 | - public function __set(string $property, $value){ |
|
| 69 | + public function __set(string $property, $value) { |
|
| 70 | 70 | |
| 71 | 71 | # if(method_exists($this, 'set_'.$property) && !$this->__isPrivate($property)){ |
| 72 | 72 | # call_user_func_array([$this, 'set_'.$property], [$value]); |
@@ -74,12 +74,12 @@ discard block |
||
| 74 | 74 | # } |
| 75 | 75 | |
| 76 | 76 | // avoid overwriting private properties |
| 77 | - if(property_exists($this, $property) && !$this->__isPrivate($property)){ |
|
| 77 | + if (property_exists($this, $property) && !$this->__isPrivate($property)) { |
|
| 78 | 78 | $this->{$property} = $value; |
| 79 | 79 | return; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if(property_exists($this, 'env') && $this->env instanceof DotEnv){ |
|
| 82 | + if (property_exists($this, 'env') && $this->env instanceof DotEnv) { |
|
| 83 | 83 | $this->env->set($property, $value); |
| 84 | 84 | return; |
| 85 | 85 | } |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return void |
| 113 | 113 | */ |
| 114 | - public function __unset(string $property){ |
|
| 114 | + public function __unset(string $property) { |
|
| 115 | 115 | |
| 116 | 116 | // avoid unsetting private properties |
| 117 | - if($this->__isset($property)){ |
|
| 117 | + if ($this->__isset($property)) { |
|
| 118 | 118 | unset($this->{$property}); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | public function __toArray():array{ |
| 134 | 134 | $data = []; |
| 135 | 135 | |
| 136 | - foreach($this as $property => $value){ |
|
| 136 | + foreach ($this as $property => $value) { |
|
| 137 | 137 | |
| 138 | 138 | // exclude private properties |
| 139 | - if($this->__isset($property)){ |
|
| 139 | + if ($this->__isset($property)) { |
|
| 140 | 140 | $data[$property] = $value; |
| 141 | 141 | } |
| 142 | 142 | |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @return $this |
| 152 | 152 | */ |
| 153 | - public function __fromIterable(array $properties){ |
|
| 153 | + public function __fromIterable(array $properties) { |
|
| 154 | 154 | |
| 155 | - foreach($properties as $key => $value){ |
|
| 155 | + foreach ($properties as $key => $value) { |
|
| 156 | 156 | $this->__set($key, $value); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * |
| 174 | 174 | * @return $this |
| 175 | 175 | */ |
| 176 | - public function __fromJSON(string $json){ |
|
| 176 | + public function __fromJSON(string $json) { |
|
| 177 | 177 | return $this->__fromIterable(json_decode($json, true)); |
| 178 | 178 | } |
| 179 | 179 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * @link http://api.prototypejs.org/language/Enumerable/ |
| 17 | 17 | */ |
| 18 | -trait Enumerable{ |
|
| 18 | +trait Enumerable { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @var array |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return $this |
| 47 | 47 | */ |
| 48 | - public function __each(callable $callback){ |
|
| 48 | + public function __each(callable $callback) { |
|
| 49 | 49 | $this->__map($callback); |
| 50 | 50 | |
| 51 | 51 | return $this; |
@@ -62,13 +62,13 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function __map($callback):array { |
| 64 | 64 | |
| 65 | - if(!is_callable($callback)){ |
|
| 65 | + if (!is_callable($callback)) { |
|
| 66 | 66 | throw new TraitException('invalid callback'); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | $return = []; |
| 70 | 70 | |
| 71 | - foreach($this->array as $index => $element){ |
|
| 71 | + foreach ($this->array as $index => $element) { |
|
| 72 | 72 | $return[$index] = call_user_func_array($callback, [$element, $index]); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return $this |
| 82 | 82 | */ |
| 83 | - public function __reverse(){ |
|
| 83 | + public function __reverse() { |
|
| 84 | 84 | $this->array = array_reverse($this->array); |
| 85 | 85 | $this->offset = 0; |
| 86 | 86 | |
@@ -90,21 +90,21 @@ discard block |
||
| 90 | 90 | /** |
| 91 | 91 | * @return mixed |
| 92 | 92 | */ |
| 93 | - public function __first(){ |
|
| 93 | + public function __first() { |
|
| 94 | 94 | return $this->array[0] ?? null; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | 98 | * @return mixed |
| 99 | 99 | */ |
| 100 | - public function __last(){ |
|
| 100 | + public function __last() { |
|
| 101 | 101 | return $this->array[count($this->array) - 1] ?? null; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | 105 | * @return $this |
| 106 | 106 | */ |
| 107 | - public function __clear(){ |
|
| 107 | + public function __clear() { |
|
| 108 | 108 | $this->array = []; |
| 109 | 109 | |
| 110 | 110 | return $this; |
@@ -129,15 +129,15 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function __findAll(callable $callback):array{ |
| 131 | 131 | |
| 132 | - if(!is_callable($callback)){ |
|
| 132 | + if (!is_callable($callback)) { |
|
| 133 | 133 | throw new TraitException('invalid callback'); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | $return = []; |
| 137 | 137 | |
| 138 | - foreach($this->array as $index => $element){ |
|
| 138 | + foreach ($this->array as $index => $element) { |
|
| 139 | 139 | |
| 140 | - if(call_user_func_array($callback, [$element, $index]) === true){ |
|
| 140 | + if (call_user_func_array($callback, [$element, $index]) === true) { |
|
| 141 | 141 | $return[] = $element; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -156,15 +156,15 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public function __reject(callable $callback):array{ |
| 158 | 158 | |
| 159 | - if(!is_callable($callback)){ |
|
| 159 | + if (!is_callable($callback)) { |
|
| 160 | 160 | throw new TraitException('invalid callback'); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | $return = []; |
| 164 | 164 | |
| 165 | - foreach($this->array as $index => $element){ |
|
| 165 | + foreach ($this->array as $index => $element) { |
|
| 166 | 166 | |
| 167 | - if(call_user_func_array($callback, [$element, $index]) !== true){ |
|
| 167 | + if (call_user_func_array($callback, [$element, $index]) !== true) { |
|
| 168 | 168 | $return[] = $element; |
| 169 | 169 | } |
| 170 | 170 | |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | public function __equal(array $y):bool{ |
| 182 | 182 | |
| 183 | - if(count($this->array) !== count($y)){ |
|
| 183 | + if (count($this->array) !== count($y)) { |
|
| 184 | 184 | return false; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | $diff = 0; |
| 188 | 188 | |
| 189 | - foreach($this->array as $kx => $vx){ |
|
| 189 | + foreach ($this->array as $kx => $vx) { |
|
| 190 | 190 | $diff |= $vx ^ $y[$kx]; |
| 191 | 191 | } |
| 192 | 192 | |