@@ -12,4 +12,4 @@ |
||
| 12 | 12 | |
| 13 | 13 | namespace chillerlan\Traits; |
| 14 | 14 | |
| 15 | -class TraitException extends \Exception{} |
|
| 15 | +class TraitException extends \Exception {} |
|
@@ -50,8 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | if($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)){ |
| 52 | 52 | trigger_error($class.' does not implement '.$type); |
| 53 | - } |
|
| 54 | - elseif(!$reflectionClass->isSubclassOf($type)) { |
|
| 53 | + } elseif(!$reflectionClass->isSubclassOf($type)) { |
|
| 55 | 54 | trigger_error($class.' does not inherit '.$type); |
| 56 | 55 | } |
| 57 | 56 | |
@@ -64,8 +63,7 @@ discard block |
||
| 64 | 63 | } |
| 65 | 64 | |
| 66 | 65 | return $object; |
| 67 | - } |
|
| 68 | - catch(Exception $e){ |
|
| 66 | + } catch(Exception $e){ |
|
| 69 | 67 | throw new TraitException('ClassLoader: '.$e->getMessage()); |
| 70 | 68 | } |
| 71 | 69 | |
@@ -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,31 +27,31 @@ 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 === null ? $class : $type; |
| 32 | 32 | |
| 33 | - try{ |
|
| 33 | + try { |
|
| 34 | 34 | $reflectionClass = new ReflectionClass($class); |
| 35 | 35 | $reflectionType = new ReflectionClass($type); |
| 36 | 36 | |
| 37 | - if($reflectionType->isTrait()){ |
|
| 37 | + if ($reflectionType->isTrait()) { |
|
| 38 | 38 | trigger_error($class.' cannot be an instance of trait '.$type); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - if($reflectionClass->isAbstract()){ |
|
| 41 | + if ($reflectionClass->isAbstract()) { |
|
| 42 | 42 | trigger_error('cannot instance abstract class '.$class); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if($reflectionClass->isTrait()){ |
|
| 45 | + if ($reflectionClass->isTrait()) { |
|
| 46 | 46 | trigger_error('cannot instance trait '.$class); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if($class !== $type){ |
|
| 49 | + if ($class !== $type) { |
|
| 50 | 50 | |
| 51 | - if($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)){ |
|
| 51 | + if ($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)) { |
|
| 52 | 52 | trigger_error($class.' does not implement '.$type); |
| 53 | 53 | } |
| 54 | - elseif(!$reflectionClass->isSubclassOf($type)) { |
|
| 54 | + elseif (!$reflectionClass->isSubclassOf($type)) { |
|
| 55 | 55 | trigger_error($class.' does not inherit '.$type); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -59,13 +59,13 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $object = $reflectionClass->newInstanceArgs($params); |
| 61 | 61 | |
| 62 | - if(!$object instanceof $type){ |
|
| 62 | + if (!$object instanceof $type) { |
|
| 63 | 63 | trigger_error('how did u even get here?'); // @codeCoverageIgnore |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | return $object; |
| 67 | 67 | } |
| 68 | - catch(Exception $e){ |
|
| 68 | + catch (Exception $e) { |
|
| 69 | 69 | throw new TraitException('ClassLoader: '.$e->getMessage()); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * A Container that turns methods into magic properties |
| 17 | 17 | */ |
| 18 | -trait Magic{ |
|
| 18 | +trait Magic { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @param string $name |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | private function set(string $name, $value) { |
| 57 | 57 | $method = 'magic_set_'.$name; |
| 58 | 58 | |
| 59 | - if(method_exists($this, $method)){ |
|
| 59 | + if (method_exists($this, $method)) { |
|
| 60 | 60 | $this->$method($value); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -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($callback){ |
|
| 48 | + public function __each($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 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | namespace chillerlan\Traits; |
| 14 | 14 | |
| 15 | -class DotEnv{ |
|
| 15 | +class DotEnv { |
|
| 16 | 16 | use Env; |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param string $path |
| 32 | 32 | * @param string|null $filename |
| 33 | 33 | */ |
| 34 | - public function __construct(string $path, string $filename = null){ |
|
| 34 | + public function __construct(string $path, string $filename = null) { |
|
| 35 | 35 | $this->path = $path; |
| 36 | 36 | $this->filename = $filename; |
| 37 | 37 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return bool|mixed |
| 64 | 64 | */ |
| 65 | - public function get(string $var){ |
|
| 65 | + public function get(string $var) { |
|
| 66 | 66 | return $this->__getEnv($var); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return $this |
| 74 | 74 | */ |
| 75 | - public function set(string $var, string $value){ |
|
| 75 | + public function set(string $var, string $value) { |
|
| 76 | 76 | return $this->__setEnv($var, $value); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -56,8 +56,7 @@ |
||
| 56 | 56 | |
| 57 | 57 | if(array_key_exists($var, $_ENV)){ |
| 58 | 58 | return $_ENV[$var]; |
| 59 | - } |
|
| 60 | - elseif(function_exists('getenv')){ |
|
| 59 | + } elseif(function_exists('getenv')){ |
|
| 61 | 60 | if($e = getenv($var) !== false){ |
| 62 | 61 | return $e; |
| 63 | 62 | } |
@@ -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 |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return $this |
| 40 | 40 | */ |
| 41 | - protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null){ |
|
| 41 | + protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null) { |
|
| 42 | 42 | $overwrite = $overwrite !== null ? $overwrite : false; |
| 43 | 43 | $content = $this->__read(rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.($filename ?? '.env')); |
| 44 | 44 | |
@@ -53,20 +53,20 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return bool|mixed |
| 55 | 55 | */ |
| 56 | - protected function __getEnv(string $var){ |
|
| 56 | + protected function __getEnv(string $var) { |
|
| 57 | 57 | $var = strtoupper($var); |
| 58 | 58 | |
| 59 | - if(array_key_exists($var, $_ENV)){ |
|
| 59 | + if (array_key_exists($var, $_ENV)) { |
|
| 60 | 60 | return $_ENV[$var]; |
| 61 | 61 | } |
| 62 | - elseif(function_exists('getenv')){ |
|
| 63 | - if($e = getenv($var) !== false){ |
|
| 62 | + elseif (function_exists('getenv')) { |
|
| 63 | + if ($e = getenv($var) !== false) { |
|
| 64 | 64 | return $e; |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | // @codeCoverageIgnoreStart |
| 68 | - elseif(function_exists('apache_getenv')){ |
|
| 69 | - if($e = apache_getenv($var) !== false){ |
|
| 68 | + elseif (function_exists('apache_getenv')) { |
|
| 69 | + if ($e = apache_getenv($var) !== false) { |
|
| 70 | 70 | return $e; |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @return $this |
| 83 | 83 | */ |
| 84 | - protected function __setEnv(string $var, string $value = null){ |
|
| 84 | + protected function __setEnv(string $var, string $value = null) { |
|
| 85 | 85 | $var = strtoupper($var); |
| 86 | 86 | $value = $this->__parse($value); |
| 87 | 87 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $this->_ENV[$var] = $value; |
| 94 | 94 | |
| 95 | 95 | // @codeCoverageIgnoreStart |
| 96 | - if(function_exists('apache_setenv')){ |
|
| 96 | + if (function_exists('apache_setenv')) { |
|
| 97 | 97 | apache_setenv($var, $value); |
| 98 | 98 | } |
| 99 | 99 | // @codeCoverageIgnoreEnd |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @return $this |
| 108 | 108 | */ |
| 109 | - protected function __unsetEnv(string $var){ |
|
| 109 | + protected function __unsetEnv(string $var) { |
|
| 110 | 110 | $var = strtoupper($var); |
| 111 | 111 | |
| 112 | 112 | unset($_ENV[$var]); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * |
| 122 | 122 | * @return $this |
| 123 | 123 | */ |
| 124 | - protected function __clearEnv(){ |
|
| 124 | + protected function __clearEnv() { |
|
| 125 | 125 | $_ENV = []; |
| 126 | 126 | $this->_ENV = []; |
| 127 | 127 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | private function __read(string $file):array{ |
| 138 | 138 | |
| 139 | - if(!is_readable($file) || !is_file($file)){ |
|
| 139 | + if (!is_readable($file) || !is_file($file)) { |
|
| 140 | 140 | throw new TraitException('invalid file: '.$file); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
| 147 | 147 | ini_set('auto_detect_line_endings', $autodetect); |
| 148 | 148 | |
| 149 | - if(!is_array($lines) || empty($lines)){ |
|
| 149 | + if (!is_array($lines) || empty($lines)) { |
|
| 150 | 150 | throw new TraitException('error while reading file: '.$file); |
| 151 | 151 | } |
| 152 | 152 | |
@@ -159,19 +159,19 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return $this |
| 161 | 161 | */ |
| 162 | - private function __load(array $data, bool $overwrite){ |
|
| 162 | + private function __load(array $data, bool $overwrite) { |
|
| 163 | 163 | |
| 164 | - foreach($data as $line){ |
|
| 164 | + foreach ($data as $line) { |
|
| 165 | 165 | |
| 166 | 166 | // skip empty lines and comments |
| 167 | - if(empty($line) || strpos($line, '#') === 0){ |
|
| 167 | + if (empty($line) || strpos($line, '#') === 0) { |
|
| 168 | 168 | continue; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | $kv = array_map('trim', explode('=', $line, 2)); |
| 172 | 172 | |
| 173 | 173 | // skip empty and numeric keys, keys with spaces, existing keys that shall not be overwritten |
| 174 | - if(empty($kv[0]) || is_numeric($kv[0]) || strpos($kv[0], ' ') !== false || (!$overwrite && $this->__getEnv($kv[0]) !== false)){ |
|
| 174 | + if (empty($kv[0]) || is_numeric($kv[0]) || strpos($kv[0], ' ') !== false || (!$overwrite && $this->__getEnv($kv[0]) !== false)) { |
|
| 175 | 175 | continue; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | * @return string|null |
| 188 | 188 | */ |
| 189 | - private function __parse(string $value = null){ |
|
| 189 | + private function __parse(string $value = null) { |
|
| 190 | 190 | |
| 191 | - if($value !== null){ |
|
| 191 | + if ($value !== null) { |
|
| 192 | 192 | |
| 193 | 193 | $q = $value[0] ?? null; |
| 194 | 194 | |
@@ -202,8 +202,8 @@ discard block |
||
| 202 | 202 | $value = implode(PHP_EOL, explode('\\n', $value)); |
| 203 | 203 | |
| 204 | 204 | // handle nested ${VARS} |
| 205 | - if(strpos($value, '$') !== false){ |
|
| 206 | - $value = preg_replace_callback('/\${([_a-z\d]+)}/i', function($matches){ |
|
| 205 | + if (strpos($value, '$') !== false) { |
|
| 206 | + $value = preg_replace_callback('/\${([_a-z\d]+)}/i', function($matches) { |
|
| 207 | 207 | return $this->__getEnv($matches[1]); |
| 208 | 208 | }, $value); |
| 209 | 209 | } |
@@ -219,14 +219,14 @@ discard block |
||
| 219 | 219 | * @return $this |
| 220 | 220 | * @throws \chillerlan\Traits\TraitException |
| 221 | 221 | */ |
| 222 | - private function __check(array $required = null){ |
|
| 222 | + private function __check(array $required = null) { |
|
| 223 | 223 | |
| 224 | - if($required === null || empty($required)){ |
|
| 224 | + if ($required === null || empty($required)) { |
|
| 225 | 225 | return $this; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - foreach($required as $var){ |
|
| 229 | - if($this->__getEnv($var) === false || $this->__getEnv($var) === null){ |
|
| 228 | + foreach ($required as $var) { |
|
| 229 | + if ($this->__getEnv($var) === false || $this->__getEnv($var) === null) { |
|
| 230 | 230 | throw new TraitException('required variable not set: '.strtoupper($var)); |
| 231 | 231 | } |
| 232 | 232 | } |
@@ -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,12 +49,12 @@ 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 | - if(is_null($offset)){ |
|
| 54 | + if (is_null($offset)) { |
|
| 55 | 55 | $this->array[] = $value; |
| 56 | 56 | } |
| 57 | - else{ |
|
| 57 | + else { |
|
| 58 | 58 | $this->array[$offset] = $value; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @link http://php.net/manual/arrayaccess.offsetunset.php |
| 65 | 65 | * @inheritdoc |
| 66 | 66 | */ |
| 67 | - public function offsetUnset($offset){ |
|
| 67 | + public function offsetUnset($offset) { |
|
| 68 | 68 | unset($this->array[$offset]); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -53,8 +53,7 @@ |
||
| 53 | 53 | |
| 54 | 54 | if(is_null($offset)){ |
| 55 | 55 | $this->array[] = $value; |
| 56 | - } |
|
| 57 | - else{ |
|
| 56 | + } else{ |
|
| 58 | 57 | $this->array[$offset] = $value; |
| 59 | 58 | } |
| 60 | 59 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @link http://php.net/manual/class.traversable.php |
| 20 | 20 | */ |
| 21 | -trait IteratorTrait{ |
|
| 21 | +trait IteratorTrait { |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * @var array |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @link http://php.net/manual/iterator.current.php |
| 35 | 35 | * @inheritdoc |
| 36 | 36 | */ |
| 37 | - public function current(){ |
|
| 37 | + public function current() { |
|
| 38 | 38 | return $this->array[$this->offset] ?? null; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @link http://php.net/manual/iterator.next.php |
| 43 | 43 | * @inheritdoc |
| 44 | 44 | */ |
| 45 | - public function next(){ |
|
| 45 | + public function next() { |
|
| 46 | 46 | $this->offset++; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @link http://php.net/manual/iterator.key.php |
| 51 | 51 | * @inheritdoc |
| 52 | 52 | */ |
| 53 | - public function key(){ |
|
| 53 | + public function key() { |
|
| 54 | 54 | return $this->offset; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @link http://php.net/manual/iterator.rewind.php |
| 67 | 67 | * @inheritdoc |
| 68 | 68 | */ |
| 69 | - public function rewind(){ |
|
| 69 | + public function rewind() { |
|
| 70 | 70 | $this->offset = 0; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @link http://php.net/manual/class.serializable.php |
| 19 | 19 | */ |
| 20 | -trait SerializableTrait{ |
|
| 20 | +trait SerializableTrait { |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * @var array |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @link http://php.net/manual/serializable.unserialize.php |
| 37 | 37 | * @inheritdoc |
| 38 | 38 | */ |
| 39 | - public function unserialize($serialized){ |
|
| 39 | + public function unserialize($serialized) { |
|
| 40 | 40 | $this->array = unserialize($serialized); |
| 41 | 41 | } |
| 42 | 42 | |