@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @link http://php.net/variables-order |
22 | 22 | * |
23 | 23 | */ |
24 | -trait Env{ |
|
24 | +trait Env { |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * a backup environment in case everything goes downhill |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return $this |
49 | 49 | */ |
50 | - protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null, bool $global = null){ |
|
50 | + protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null, bool $global = null) { |
|
51 | 51 | $this->_global = $global !== null ? $global : false; |
52 | 52 | $content = $this->__read(rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.($filename ?? '.env')); |
53 | 53 | |
@@ -62,20 +62,20 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return bool|mixed |
64 | 64 | */ |
65 | - protected function __getEnv(string $var){ |
|
65 | + protected function __getEnv(string $var) { |
|
66 | 66 | $var = strtoupper($var); |
67 | 67 | $env = null; |
68 | 68 | |
69 | - if($this->_global === true){ |
|
69 | + if ($this->_global === true) { |
|
70 | 70 | |
71 | - if(array_key_exists($var, $_ENV)){ |
|
71 | + if (array_key_exists($var, $_ENV)) { |
|
72 | 72 | $env = $_ENV[$var]; |
73 | 73 | } |
74 | - elseif(function_exists('getenv')){ |
|
74 | + elseif (function_exists('getenv')) { |
|
75 | 75 | $env = getenv($var); |
76 | 76 | } |
77 | 77 | // @codeCoverageIgnoreStart |
78 | - elseif(function_exists('apache_getenv')){ |
|
78 | + elseif (function_exists('apache_getenv')) { |
|
79 | 79 | $env = apache_getenv($var); |
80 | 80 | } |
81 | 81 | // @codeCoverageIgnoreEnd |
@@ -91,18 +91,18 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return $this |
93 | 93 | */ |
94 | - protected function __setEnv(string $var, string $value = null){ |
|
94 | + protected function __setEnv(string $var, string $value = null) { |
|
95 | 95 | $var = strtoupper($var); |
96 | 96 | $value = $this->__parse($value); |
97 | 97 | |
98 | - if($this->_global === true){ |
|
98 | + if ($this->_global === true) { |
|
99 | 99 | putenv($var.'='.$value); |
100 | 100 | |
101 | 101 | // fill $_ENV explicitly, assuming variables_order="GPCS" (production) |
102 | 102 | $_ENV[$var] = $value; |
103 | 103 | |
104 | 104 | // @codeCoverageIgnoreStart |
105 | - if(function_exists('apache_setenv')){ |
|
105 | + if (function_exists('apache_setenv')) { |
|
106 | 106 | apache_setenv($var, $value); |
107 | 107 | } |
108 | 108 | // @codeCoverageIgnoreEnd |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return $this |
121 | 121 | */ |
122 | - protected function __unsetEnv(string $var){ |
|
122 | + protected function __unsetEnv(string $var) { |
|
123 | 123 | $var = strtoupper($var); |
124 | 124 | |
125 | - if($this->_global === true){ |
|
125 | + if ($this->_global === true) { |
|
126 | 126 | unset($_ENV[$var]); |
127 | 127 | putenv($var); |
128 | 128 | } |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @return $this |
139 | 139 | */ |
140 | - protected function __clearEnv(){ |
|
140 | + protected function __clearEnv() { |
|
141 | 141 | |
142 | - if($this->_global === true){ |
|
142 | + if ($this->_global === true) { |
|
143 | 143 | $_ENV = []; |
144 | 144 | } |
145 | 145 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | private function __read(string $file):array{ |
158 | 158 | |
159 | - if(!is_readable($file) || !is_file($file)){ |
|
159 | + if (!is_readable($file) || !is_file($file)) { |
|
160 | 160 | throw new TraitException('invalid file: '.$file); |
161 | 161 | } |
162 | 162 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | $lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
167 | 167 | ini_set('auto_detect_line_endings', $autodetect); |
168 | 168 | |
169 | - if(!is_array($lines) || empty($lines)){ |
|
169 | + if (!is_array($lines) || empty($lines)) { |
|
170 | 170 | throw new TraitException('error while reading file: '.$file); |
171 | 171 | } |
172 | 172 | |
@@ -179,19 +179,19 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return $this |
181 | 181 | */ |
182 | - private function __load(array $data, bool $overwrite){ |
|
182 | + private function __load(array $data, bool $overwrite) { |
|
183 | 183 | |
184 | - foreach($data as $line){ |
|
184 | + foreach ($data as $line) { |
|
185 | 185 | |
186 | 186 | // skip empty lines and comments |
187 | - if(empty($line) || strpos($line, '#') === 0){ |
|
187 | + if (empty($line) || strpos($line, '#') === 0) { |
|
188 | 188 | continue; |
189 | 189 | } |
190 | 190 | |
191 | 191 | $kv = array_map('trim', explode('=', $line, 2)); |
192 | 192 | |
193 | 193 | // skip empty and numeric keys, keys with spaces, existing keys that shall not be overwritten |
194 | - if(empty($kv[0]) || is_numeric($kv[0]) || strpos($kv[0], ' ') !== false || (!$overwrite && $this->__getEnv($kv[0]) !== false)){ |
|
194 | + if (empty($kv[0]) || is_numeric($kv[0]) || strpos($kv[0], ' ') !== false || (!$overwrite && $this->__getEnv($kv[0]) !== false)) { |
|
195 | 195 | continue; |
196 | 196 | } |
197 | 197 | |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return string|null |
208 | 208 | */ |
209 | - private function __parse(string $value = null){ |
|
209 | + private function __parse(string $value = null) { |
|
210 | 210 | |
211 | - if($value !== null){ |
|
211 | + if ($value !== null) { |
|
212 | 212 | |
213 | 213 | $q = $value[0] ?? null; |
214 | 214 | |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | $value = implode(PHP_EOL, explode('\\n', $value)); |
223 | 223 | |
224 | 224 | // handle nested ${VARS} |
225 | - if(strpos($value, '$') !== false){ |
|
226 | - $value = preg_replace_callback('/\${(?<var>[_a-z\d]+)}/i', function($matches){ |
|
225 | + if (strpos($value, '$') !== false) { |
|
226 | + $value = preg_replace_callback('/\${(?<var>[_a-z\d]+)}/i', function($matches) { |
|
227 | 227 | return $this->__getEnv($matches['var']); |
228 | 228 | }, $value); |
229 | 229 | } |
@@ -239,14 +239,14 @@ discard block |
||
239 | 239 | * @return $this |
240 | 240 | * @throws \chillerlan\Traits\TraitException |
241 | 241 | */ |
242 | - private function __check(array $required = null){ |
|
242 | + private function __check(array $required = null) { |
|
243 | 243 | |
244 | - if($required === null || empty($required)){ |
|
244 | + if ($required === null || empty($required)) { |
|
245 | 245 | return $this; |
246 | 246 | } |
247 | 247 | |
248 | - foreach($required as $var){ |
|
249 | - if($this->__getEnv($var) === false || $this->__getEnv($var) === null){ |
|
248 | + foreach ($required as $var) { |
|
249 | + if ($this->__getEnv($var) === false || $this->__getEnv($var) === null) { |
|
250 | 250 | throw new TraitException('required variable not set: '.strtoupper($var)); |
251 | 251 | } |
252 | 252 | } |
@@ -70,8 +70,7 @@ |
||
70 | 70 | |
71 | 71 | if(array_key_exists($var, $_ENV)){ |
72 | 72 | $env = $_ENV[$var]; |
73 | - } |
|
74 | - elseif(function_exists('getenv')){ |
|
73 | + } elseif(function_exists('getenv')){ |
|
75 | 74 | $env = getenv($var); |
76 | 75 | } |
77 | 76 | // @codeCoverageIgnoreStart |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @method void unset(string $var) |
24 | 24 | * @method DotEnv clear() |
25 | 25 | */ |
26 | -class DotEnv{ |
|
26 | +class DotEnv { |
|
27 | 27 | use Env{ |
28 | 28 | // allow a magic getter & setter |
29 | 29 | __getEnv as public __get; |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param string|null $filename |
58 | 58 | * @param bool|null $global |
59 | 59 | */ |
60 | - public function __construct(string $path, string $filename = null, bool $global = null){ |
|
60 | + public function __construct(string $path, string $filename = null, bool $global = null) { |
|
61 | 61 | $this->path = $path; |
62 | 62 | $this->filename = $filename; |
63 | 63 | $this->_global = $global ?? true; // emulate vlucas/dotenv behaviour by default |
@@ -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,12 +28,12 @@ discard block |
||
28 | 28 | * @param array $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 | |
36 | - foreach($properties as $key => $value){ |
|
36 | + foreach ($properties as $key => $value) { |
|
37 | 37 | $this->__set($key, $value); |
38 | 38 | } |
39 | 39 | |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return mixed |
48 | 48 | */ |
49 | - public function __get(string $property){ |
|
49 | + public function __get(string $property) { |
|
50 | 50 | |
51 | - if($this->__isset($property)){ |
|
51 | + if ($this->__isset($property)) { |
|
52 | 52 | return $this->{$property}; |
53 | 53 | } |
54 | - elseif($this->env instanceof DotEnv){ |
|
54 | + elseif ($this->env instanceof DotEnv) { |
|
55 | 55 | return $this->env->get($property); |
56 | 56 | } |
57 | 57 | |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return void |
66 | 66 | */ |
67 | - public function __set(string $property, $value){ |
|
67 | + public function __set(string $property, $value) { |
|
68 | 68 | |
69 | 69 | // avoid overwriting private properties |
70 | - if(!property_exists($this, $property) || !$this->__isPrivate($property)){ |
|
70 | + if (!property_exists($this, $property) || !$this->__isPrivate($property)) { |
|
71 | 71 | $this->{$property} = $value; |
72 | 72 | } |
73 | - elseif($this->env instanceof DotEnv){ |
|
73 | + elseif ($this->env instanceof DotEnv) { |
|
74 | 74 | $this->env->set($property, $value); |
75 | 75 | } |
76 | 76 | |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return void |
101 | 101 | */ |
102 | - public function __unset(string $property){ |
|
102 | + public function __unset(string $property) { |
|
103 | 103 | |
104 | 104 | // avoid unsetting private properties |
105 | - if($this->__isPrivate($property)){ |
|
105 | + if ($this->__isPrivate($property)) { |
|
106 | 106 | unset($this->{$property}); |
107 | 107 | } |
108 | 108 | |
@@ -121,10 +121,10 @@ discard block |
||
121 | 121 | public function __toArray():array{ |
122 | 122 | $data = []; |
123 | 123 | |
124 | - foreach($this as $property => $value){ |
|
124 | + foreach ($this as $property => $value) { |
|
125 | 125 | |
126 | 126 | // exclude private properties |
127 | - if($this->__isset($property)){ |
|
127 | + if ($this->__isset($property)) { |
|
128 | 128 | $data[$property] = $value; |
129 | 129 | } |
130 | 130 |
@@ -50,8 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | if($this->__isset($property)){ |
52 | 52 | return $this->{$property}; |
53 | - } |
|
54 | - elseif($this->env instanceof DotEnv){ |
|
53 | + } elseif($this->env instanceof DotEnv){ |
|
55 | 54 | return $this->env->get($property); |
56 | 55 | } |
57 | 56 | |
@@ -69,8 +68,7 @@ discard block |
||
69 | 68 | // avoid overwriting private properties |
70 | 69 | if(!property_exists($this, $property) || !$this->__isPrivate($property)){ |
71 | 70 | $this->{$property} = $value; |
72 | - } |
|
73 | - elseif($this->env instanceof DotEnv){ |
|
71 | + } elseif($this->env instanceof DotEnv){ |
|
74 | 72 | $this->env->set($property, $value); |
75 | 73 | } |
76 | 74 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @link http://api.prototypejs.org/language/Enumerable/ |
19 | 19 | */ |
20 | -trait Enumerable{ |
|
20 | +trait Enumerable { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @var array |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return $this |
49 | 49 | */ |
50 | - public function __each($callback){ |
|
50 | + public function __each($callback) { |
|
51 | 51 | $this->__map($callback); |
52 | 52 | |
53 | 53 | return $this; |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function __map($callback):array { |
66 | 66 | |
67 | - if(!is_callable($callback)){ |
|
67 | + if (!is_callable($callback)) { |
|
68 | 68 | throw new TraitException('invalid callback'); |
69 | 69 | } |
70 | 70 | |
71 | 71 | $return = []; |
72 | 72 | |
73 | - foreach($this->array as $index => $element){ |
|
73 | + foreach ($this->array as $index => $element) { |
|
74 | 74 | $return[$index] = call_user_func_array($callback, [$element, $index]); |
75 | 75 | } |
76 | 76 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return $this |
84 | 84 | */ |
85 | - public function __reverse(){ |
|
85 | + public function __reverse() { |
|
86 | 86 | $this->array = array_reverse($this->array); |
87 | 87 | $this->offset = 0; |
88 | 88 | |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * @return mixed |
94 | 94 | */ |
95 | - public function __last(){ |
|
95 | + public function __last() { |
|
96 | 96 | return $this->array[count($this->array) - 1]; |
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * @return $this |
101 | 101 | */ |
102 | - public function __clear(){ |
|
102 | + public function __clear() { |
|
103 | 103 | $this->array = []; |
104 | 104 | |
105 | 105 | return $this; |
@@ -124,15 +124,15 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function __findAll(Closure $callback):array{ |
126 | 126 | |
127 | - if(!is_callable($callback)){ |
|
127 | + if (!is_callable($callback)) { |
|
128 | 128 | throw new TraitException('invalid callback'); |
129 | 129 | } |
130 | 130 | |
131 | 131 | $return = []; |
132 | 132 | |
133 | - foreach($this->array as $index => $element){ |
|
133 | + foreach ($this->array as $index => $element) { |
|
134 | 134 | |
135 | - if(call_user_func_array($callback, [$element, $index]) === true){ |
|
135 | + if (call_user_func_array($callback, [$element, $index]) === true) { |
|
136 | 136 | $return[] = $element; |
137 | 137 | } |
138 | 138 | |
@@ -151,15 +151,15 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function __reject(Closure $callback):array{ |
153 | 153 | |
154 | - if(!is_callable($callback)){ |
|
154 | + if (!is_callable($callback)) { |
|
155 | 155 | throw new TraitException('invalid callback'); |
156 | 156 | } |
157 | 157 | |
158 | 158 | $return = []; |
159 | 159 | |
160 | - foreach($this->array as $index => $element){ |
|
160 | + foreach ($this->array as $index => $element) { |
|
161 | 161 | |
162 | - if(call_user_func_array($callback, [$element, $index]) !== true){ |
|
162 | + if (call_user_func_array($callback, [$element, $index]) !== true) { |
|
163 | 163 | $return[] = $element; |
164 | 164 | } |
165 | 165 | |
@@ -175,13 +175,13 @@ discard block |
||
175 | 175 | */ |
176 | 176 | public function __equal(array $y):bool{ |
177 | 177 | |
178 | - if(count($this->array) !== count($y)){ |
|
178 | + if (count($this->array) !== count($y)) { |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | |
182 | 182 | $diff = 0; |
183 | 183 | |
184 | - foreach($this->array as $kx => $vx){ |
|
184 | + foreach ($this->array as $kx => $vx) { |
|
185 | 185 | $diff |= $vx ^ $y[$kx]; |
186 | 186 | } |
187 | 187 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @extends \SplFixedArray |
19 | 19 | */ |
20 | -class ByteArray extends SplFixedArray{ |
|
20 | +class ByteArray extends SplFixedArray { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @return string |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @return string |
31 | 31 | */ |
32 | 32 | public function toHex():string{ |
33 | - return $this->map(function($v){ |
|
33 | + return $this->map(function($v) { |
|
34 | 34 | return str_pad(dechex($v), '2', '0', STR_PAD_LEFT); |
35 | 35 | }); |
36 | 36 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @return string |
54 | 54 | */ |
55 | 55 | public function toBin():string{ |
56 | - return $this->map(function($v){ |
|
56 | + return $this->map(function($v) { |
|
57 | 57 | return str_pad(decbin($v), '8', '0', STR_PAD_LEFT); |
58 | 58 | }); |
59 | 59 | } |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | |
83 | 83 | $diff = $offset + $length; |
84 | 84 | |
85 | - if($diff > $this->count()){ |
|
85 | + if ($diff > $this->count()) { |
|
86 | 86 | $this->setSize($diff); |
87 | 87 | } |
88 | 88 | |
89 | - for($i = 0; $i < $length; $i++){ |
|
89 | + for ($i = 0; $i < $length; $i++) { |
|
90 | 90 | $this[$i + $offset] = $src[$i + $srcOffset]; |
91 | 91 | } |
92 | 92 | |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | |
104 | 104 | // keep an extended class |
105 | 105 | /** @var \chillerlan\Traits\ArrayHelpers\ByteArray $slice */ |
106 | - $slice = (new ReflectionClass($this))->newInstanceArgs([$length ?? ($this->count() - $offset)]); |
|
106 | + $slice = (new ReflectionClass($this))->newInstanceArgs([$length ?? ($this->count() - $offset)]); |
|
107 | 107 | |
108 | - foreach($slice as $i => $_){ |
|
108 | + foreach ($slice as $i => $_) { |
|
109 | 109 | $slice[$i] = $this[$offset + $i]; |
110 | 110 | } |
111 | 111 | |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function equal(SplFixedArray $array):bool{ |
121 | 121 | |
122 | - if($this->count() !== $array->count()){ |
|
122 | + if ($this->count() !== $array->count()) { |
|
123 | 123 | return false; |
124 | 124 | } |
125 | 125 | |
126 | 126 | $diff = 0; |
127 | 127 | |
128 | - foreach($this as $k => $v){ |
|
128 | + foreach ($this as $k => $v) { |
|
129 | 129 | $diff |= $v ^ $array[$k]; |
130 | 130 | } |
131 | 131 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @link http://php.net/manual/class.arrayaccess.php |
19 | 19 | */ |
20 | -trait ArrayAccessTrait{ |
|
20 | +trait ArrayAccessTrait { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @var array |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @link http://php.net/manual/arrayaccess.offsetget.php |
42 | 42 | * @inheritdoc |
43 | 43 | */ |
44 | - public function offsetGet($offset){ |
|
44 | + public function offsetGet($offset) { |
|
45 | 45 | return $this->array[$offset] ?? null; |
46 | 46 | } |
47 | 47 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @link http://php.net/manual/arrayaccess.offsetset.php |
50 | 50 | * @inheritdoc |
51 | 51 | */ |
52 | - public function offsetSet($offset, $value){ |
|
52 | + public function offsetSet($offset, $value) { |
|
53 | 53 | |
54 | 54 | $offset !== null |
55 | 55 | ? $this->array[$offset] = $value |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @link http://php.net/manual/arrayaccess.offsetunset.php |
61 | 61 | * @inheritdoc |
62 | 62 | */ |
63 | - public function offsetUnset($offset){ |
|
63 | + public function offsetUnset($offset) { |
|
64 | 64 | unset($this->array[$offset]); |
65 | 65 | } |
66 | 66 |