@@ -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 $array, bool $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 | |
@@ -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 | |
@@ -21,7 +21,7 @@ discard block |
||
| 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 | /** |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | public function seek($pos):void{ |
| 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 | |