@@ -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 | |
@@ -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 | |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | * |
| 18 | 18 | * @link http://php.net/manual/class.countable.php |
| 19 | 19 | */ |
| 20 | -trait CountableTrait{ |
|
| 20 | +trait CountableTrait { |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * @var array |
@@ -21,19 +21,19 @@ |
||
| 21 | 21 | * |
| 22 | 22 | * @link http://php.net/manual/class.seekableiterator.php |
| 23 | 23 | */ |
| 24 | -trait SeekableIteratorTrait{ |
|
| 24 | +trait SeekableIteratorTrait { |
|
| 25 | 25 | use IteratorTrait; |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * @link http://php.net/manual/seekableiterator.seek.php |
| 29 | 29 | * @inheritdoc |
| 30 | 30 | */ |
| 31 | - public function seek($pos){ |
|
| 31 | + public function seek($pos) { |
|
| 32 | 32 | $this->rewind(); |
| 33 | 33 | |
| 34 | - for( ; $this->offset < $pos; ){ |
|
| 34 | + for (; $this->offset < $pos;) { |
|
| 35 | 35 | |
| 36 | - if(!next($this->array)) { |
|
| 36 | + if (!next($this->array)) { |
|
| 37 | 37 | throw new OutOfBoundsException('invalid seek position: '.$pos); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * |
| 20 | 20 | */ |
| 21 | -class ByteArrayDispenser{ |
|
| 21 | +class ByteArrayDispenser { |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * @var string |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function fromIntSize(int $size):ByteArray{ |
| 44 | 44 | |
| 45 | - if(!$this->isAllowedInt($size)){ |
|
| 45 | + if (!$this->isAllowedInt($size)) { |
|
| 46 | 46 | throw new TraitException('invalid size'); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -58,12 +58,12 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function fromArray($array, $save_indexes = null):ByteArray{ |
| 60 | 60 | |
| 61 | - try{ |
|
| 61 | + try { |
|
| 62 | 62 | $out = $this->fromIntSize(count($array)); |
| 63 | 63 | |
| 64 | 64 | $array = ($save_indexes ?? true) ? $array : array_values($array); |
| 65 | 65 | |
| 66 | - foreach($array as $k => $v){ |
|
| 66 | + foreach ($array as $k => $v) { |
|
| 67 | 67 | $out[$k] = $v; |
| 68 | 68 | } |
| 69 | 69 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | } |
| 72 | 72 | // this can be anything |
| 73 | 73 | // @codeCoverageIgnoreStart |
| 74 | - catch(Exception $e){ |
|
| 74 | + catch (Exception $e) { |
|
| 75 | 75 | throw new TraitException($e->getMessage()); |
| 76 | 76 | } |
| 77 | 77 | // @codeCoverageIgnoreEnd |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function fromArrayFill(int $len, $fill = null):ByteArray{ |
| 90 | 90 | |
| 91 | - if(!$this->isAllowedInt($len)){ |
|
| 91 | + if (!$this->isAllowedInt($len)) { |
|
| 92 | 92 | throw new TraitException('invalid length'); |
| 93 | 93 | } |
| 94 | 94 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | public function fromHex(string $hex):ByteArray{ |
| 125 | 125 | $hex = preg_replace('/[\s\r\n\t ]/', '', $hex); |
| 126 | 126 | |
| 127 | - if(!$this->isAllowedHex($hex)){ |
|
| 127 | + if (!$this->isAllowedHex($hex)) { |
|
| 128 | 128 | throw new TraitException('invalid hex string'); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | public function fromJSON(string $json):ByteArray{ |
| 152 | 152 | $json = trim($json); |
| 153 | 153 | |
| 154 | - if(!$this->isAllowedJSON($json)){ |
|
| 154 | + if (!$this->isAllowedJSON($json)) { |
|
| 155 | 155 | throw new TraitException('invalid JSON array'); |
| 156 | 156 | } |
| 157 | 157 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | public function fromBase64(string $base64):ByteArray{ |
| 179 | 179 | $base64 = trim($base64); |
| 180 | 180 | |
| 181 | - if(!$this->isAllowedBase64($base64)){ |
|
| 181 | + if (!$this->isAllowedBase64($base64)) { |
|
| 182 | 182 | throw new TraitException('invalid base64 string'); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | public function fromBin(string $bin):ByteArray{ |
| 206 | 206 | $bin = trim($bin); |
| 207 | 207 | |
| 208 | - if(!$this->isAllowedBin($bin)){ |
|
| 208 | + if (!$this->isAllowedBin($bin)) { |
|
| 209 | 209 | throw new TraitException('invalid binary string'); |
| 210 | 210 | } |
| 211 | 211 | |
@@ -220,19 +220,19 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | public function guessFrom($data):ByteArray{ |
| 222 | 222 | |
| 223 | - if($data instanceof Traversable){ |
|
| 223 | + if ($data instanceof Traversable) { |
|
| 224 | 224 | return $this->fromArray(iterator_to_array($data)); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - if(is_array($data)){ |
|
| 227 | + if (is_array($data)) { |
|
| 228 | 228 | return $this->fromArray($data); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if(is_string($data)){ |
|
| 231 | + if (is_string($data)) { |
|
| 232 | 232 | |
| 233 | - foreach(['Bin', 'Hex', 'JSON', 'Base64'] as $type){ |
|
| 233 | + foreach (['Bin', 'Hex', 'JSON', 'Base64'] as $type) { |
|
| 234 | 234 | |
| 235 | - if(call_user_func_array([$this, 'isAllowed'.$type], [$data]) === true){ |
|
| 235 | + if (call_user_func_array([$this, 'isAllowed'.$type], [$data]) === true) { |
|
| 236 | 236 | return call_user_func_array([$this, 'from'.$type], [$data]); |
| 237 | 237 | } |
| 238 | 238 | |
@@ -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 | } |