@@ -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,17 +42,17 @@ 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 | - if(method_exists($this, 'get_'.$property) && $this->__isset($property)){ |
|
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 | - elseif($this->env instanceof DotEnv){ |
|
55 | + elseif ($this->env instanceof DotEnv) { |
|
56 | 56 | return $this->env->get($property); |
57 | 57 | } |
58 | 58 | |
@@ -65,19 +65,19 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return void |
67 | 67 | */ |
68 | - public function __set(string $property, $value){ |
|
68 | + public function __set(string $property, $value) { |
|
69 | 69 | |
70 | - if(method_exists($this, 'set_'.$property) && !$this->__isPrivate($property)){ |
|
70 | + if (method_exists($this, 'set_'.$property) && !$this->__isPrivate($property)) { |
|
71 | 71 | call_user_func_array([$this, 'set_'.$property], [$value]); |
72 | 72 | |
73 | 73 | return; |
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 | } |
80 | - elseif($this->env instanceof DotEnv){ |
|
80 | + elseif ($this->env instanceof DotEnv) { |
|
81 | 81 | $this->env->set($property, $value); |
82 | 82 | } |
83 | 83 | |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @return void |
108 | 108 | */ |
109 | - public function __unset(string $property){ |
|
109 | + public function __unset(string $property) { |
|
110 | 110 | |
111 | 111 | // avoid unsetting private properties |
112 | - if($this->__isset($property)){ |
|
112 | + if ($this->__isset($property)) { |
|
113 | 113 | unset($this->{$property}); |
114 | 114 | } |
115 | 115 | |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | public function __toArray():array{ |
129 | 129 | $data = []; |
130 | 130 | |
131 | - foreach($this as $property => $value){ |
|
131 | + foreach ($this as $property => $value) { |
|
132 | 132 | |
133 | 133 | // exclude private properties |
134 | - if($this->__isset($property)){ |
|
134 | + if ($this->__isset($property)) { |
|
135 | 135 | $data[$property] = $value; |
136 | 136 | } |
137 | 137 | |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return $this |
147 | 147 | */ |
148 | - public function __fromIterable(array $properties){ |
|
148 | + public function __fromIterable(array $properties) { |
|
149 | 149 | |
150 | - foreach($properties as $key => $value){ |
|
150 | + foreach ($properties as $key => $value) { |
|
151 | 151 | $this->__set($key, $value); |
152 | 152 | } |
153 | 153 | |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return $this |
170 | 170 | */ |
171 | - public function __fromJSON(string $json){ |
|
171 | + public function __fromJSON(string $json) { |
|
172 | 172 | return $this->__fromIterable(json_decode($json, true)); |
173 | 173 | } |
174 | 174 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use Exception, ReflectionClass; |
16 | 16 | |
17 | -trait ClassLoader{ |
|
17 | +trait ClassLoader { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Instances an object of $class/$type with an arbitrary number of $params |
@@ -27,45 +27,45 @@ discard block |
||
27 | 27 | * @return mixed of type $type |
28 | 28 | * @throws \Exception |
29 | 29 | */ |
30 | - public function loadClass(string $class, string $type = null, ...$params){ |
|
30 | + public function loadClass(string $class, string $type = null, ...$params) { |
|
31 | 31 | $type = $type ?? $class; |
32 | 32 | |
33 | - try{ |
|
33 | + try { |
|
34 | 34 | $reflectionClass = new ReflectionClass($class); |
35 | 35 | $reflectionType = new ReflectionClass($type); |
36 | 36 | } |
37 | - catch(Exception $e){ |
|
37 | + catch (Exception $e) { |
|
38 | 38 | throw new TraitException('ClassLoader: '.$e->getMessage()); |
39 | 39 | } |
40 | 40 | |
41 | 41 | |
42 | - if($reflectionType->isTrait()){ |
|
42 | + if ($reflectionType->isTrait()) { |
|
43 | 43 | throw new TraitException($class.' cannot be an instance of trait '.$type); |
44 | 44 | } |
45 | 45 | |
46 | - if($reflectionClass->isAbstract()){ |
|
46 | + if ($reflectionClass->isAbstract()) { |
|
47 | 47 | throw new TraitException('cannot instance abstract class '.$class); |
48 | 48 | } |
49 | 49 | |
50 | - if($reflectionClass->isTrait()){ |
|
50 | + if ($reflectionClass->isTrait()) { |
|
51 | 51 | throw new TraitException('cannot instance trait '.$class); |
52 | 52 | } |
53 | 53 | |
54 | - if($class !== $type){ |
|
54 | + if ($class !== $type) { |
|
55 | 55 | |
56 | - if($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)){ |
|
56 | + if ($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)) { |
|
57 | 57 | throw new TraitException($class.' does not implement '.$type); |
58 | 58 | } |
59 | - elseif(!$reflectionClass->isSubclassOf($type)) { |
|
59 | + elseif (!$reflectionClass->isSubclassOf($type)) { |
|
60 | 60 | throw new TraitException($class.' does not inherit '.$type); |
61 | 61 | } |
62 | 62 | |
63 | 63 | } |
64 | 64 | |
65 | - try{ |
|
65 | + try { |
|
66 | 66 | $object = $reflectionClass->newInstanceArgs($params); |
67 | 67 | |
68 | - if(!$object instanceof $type){ |
|
68 | + if (!$object instanceof $type) { |
|
69 | 69 | throw new TraitException('how did u even get here?'); // @codeCoverageIgnore |
70 | 70 | } |
71 | 71 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | // @codeCoverageIgnoreStart |
75 | 75 | // here be dragons |
76 | - catch(Exception $e){ |
|
76 | + catch (Exception $e) { |
|
77 | 77 | throw new TraitException('ClassLoader: '.$e->getMessage()); |
78 | 78 | } |
79 | 79 | // @codeCoverageIgnoreEnd |
@@ -33,8 +33,7 @@ discard block |
||
33 | 33 | try{ |
34 | 34 | $reflectionClass = new ReflectionClass($class); |
35 | 35 | $reflectionType = new ReflectionClass($type); |
36 | - } |
|
37 | - catch(Exception $e){ |
|
36 | + } catch(Exception $e){ |
|
38 | 37 | throw new TraitException('ClassLoader: '.$e->getMessage()); |
39 | 38 | } |
40 | 39 | |
@@ -55,8 +54,7 @@ discard block |
||
55 | 54 | |
56 | 55 | if($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)){ |
57 | 56 | throw new TraitException($class.' does not implement '.$type); |
58 | - } |
|
59 | - elseif(!$reflectionClass->isSubclassOf($type)) { |
|
57 | + } elseif(!$reflectionClass->isSubclassOf($type)) { |
|
60 | 58 | throw new TraitException($class.' does not inherit '.$type); |
61 | 59 | } |
62 | 60 |
@@ -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 | /** |
@@ -27,19 +27,19 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @param array|object|\Traversable|\ArrayIterator|\ArrayObject|null $array |
29 | 29 | */ |
30 | - public function __construct($array = null){ |
|
30 | + public function __construct($array = null) { |
|
31 | 31 | |
32 | - if(($array instanceof ArrayObject) || ($array instanceof ArrayIterator)){ |
|
32 | + if (($array instanceof ArrayObject) || ($array instanceof ArrayIterator)) { |
|
33 | 33 | $this->array = $array->getArrayCopy(); |
34 | 34 | } |
35 | - elseif($array instanceof Traversable){ |
|
35 | + elseif ($array instanceof Traversable) { |
|
36 | 36 | $this->array = iterator_to_array($array); |
37 | 37 | } |
38 | 38 | // yields unexpected results with DotArray |
39 | - elseif(gettype($array) === 'object'){ |
|
39 | + elseif (gettype($array) === 'object') { |
|
40 | 40 | $this->array = get_object_vars($array); |
41 | 41 | } |
42 | - elseif(is_array($array)){ |
|
42 | + elseif (is_array($array)) { |
|
43 | 43 | $this->array = $array; |
44 | 44 | } |
45 | 45 | |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return mixed |
56 | 56 | */ |
57 | - public function searchByKey(string $dotKey){ |
|
57 | + public function searchByKey(string $dotKey) { |
|
58 | 58 | |
59 | - foreach($this->iterator as $v){ |
|
59 | + foreach ($this->iterator as $v) { |
|
60 | 60 | |
61 | - if($this->getPath() === $dotKey){ |
|
61 | + if ($this->getPath() === $dotKey) { |
|
62 | 62 | return $v; |
63 | 63 | } |
64 | 64 | |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | |
72 | 72 | $matches = []; |
73 | 73 | |
74 | - foreach($this->iterator as $v){ |
|
74 | + foreach ($this->iterator as $v) { |
|
75 | 75 | |
76 | - if($v === $value){ |
|
76 | + if ($v === $value) { |
|
77 | 77 | $matches[$this->getPath()] = $value; |
78 | 78 | } |
79 | 79 | |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function isset(string $dotKey):bool{ |
91 | 91 | |
92 | - foreach($this->iterator as $v){ |
|
92 | + foreach ($this->iterator as $v) { |
|
93 | 93 | |
94 | - if($this->getPath() === $dotKey){ |
|
94 | + if ($this->getPath() === $dotKey) { |
|
95 | 95 | return true; |
96 | 96 | } |
97 | 97 |
@@ -31,15 +31,13 @@ |
||
31 | 31 | |
32 | 32 | if(($array instanceof ArrayObject) || ($array instanceof ArrayIterator)){ |
33 | 33 | $this->array = $array->getArrayCopy(); |
34 | - } |
|
35 | - elseif($array instanceof Traversable){ |
|
34 | + } elseif($array instanceof Traversable){ |
|
36 | 35 | $this->array = iterator_to_array($array); |
37 | 36 | } |
38 | 37 | // yields unexpected results with DotArray |
39 | 38 | elseif(gettype($array) === 'object'){ |
40 | 39 | $this->array = get_object_vars($array); |
41 | - } |
|
42 | - elseif(is_array($array)){ |
|
40 | + } elseif(is_array($array)){ |
|
43 | 41 | $this->array = $array; |
44 | 42 | } |
45 | 43 |