Passed
Push — master ( 6db927...ab6235 )
by smiley
03:35
created
src/TraitException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,4 +12,4 @@
 block discarded – undo
12 12
 
13 13
 namespace chillerlan\Traits;
14 14
 
15
-class TraitException extends \Exception{}
15
+class TraitException extends \Exception {}
Please login to merge, or discard this patch.
src/SPL/CountableTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
src/ArrayHelpers/ByteArrayDispenser.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/ArrayHelpers/DotArray.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 /**
16 16
  * @link https://github.com/laravel/framework/blob/5.4/src/Illuminate/Support/Arr.php
17 17
  */
18
-trait DotArray{
18
+trait DotArray {
19 19
 
20 20
 	/**
21 21
 	 * @var array
@@ -30,17 +30,17 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @return mixed returns $array[$key], $default otherwise.
32 32
 	 */
33
-	public function get(string $dotKey, $default = null){
33
+	public function get(string $dotKey, $default = null) {
34 34
 
35
-		if(isset($this->array[$dotKey])){
35
+		if (isset($this->array[$dotKey])) {
36 36
 			return $this->array[$dotKey];
37 37
 		}
38 38
 
39 39
 		$array = &$this->array;
40 40
 
41
-		foreach(explode('.', $dotKey) as $segment){
41
+		foreach (explode('.', $dotKey) as $segment) {
42 42
 
43
-			if(!is_array($array) || !array_key_exists($segment, $array)){
43
+			if (!is_array($array) || !array_key_exists($segment, $array)) {
44 44
 				return $default;
45 45
 			}
46 46
 
@@ -59,19 +59,19 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	public function in(string $dotKey):bool{
61 61
 
62
-		if(empty($this->array)){
62
+		if (empty($this->array)) {
63 63
 			return false;
64 64
 		}
65 65
 
66
-		if(array_key_exists($dotKey, $this->array)){
66
+		if (array_key_exists($dotKey, $this->array)) {
67 67
 			return true;
68 68
 		}
69 69
 
70 70
 		$array = &$this->array;
71 71
 
72
-		foreach(explode('.', $dotKey) as $segment){
72
+		foreach (explode('.', $dotKey) as $segment) {
73 73
 
74
-			if(!is_array($array) || !array_key_exists($segment, $array)){
74
+			if (!is_array($array) || !array_key_exists($segment, $array)) {
75 75
 				return false;
76 76
 			}
77 77
 
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
 	 *
92 92
 	 * @return \chillerlan\Traits\ArrayHelpers\DotArray
93 93
 	 */
94
-	public function set(string $dotKey, $value){
94
+	public function set(string $dotKey, $value) {
95 95
 
96
-		if(empty($dotKey)){
96
+		if (empty($dotKey)) {
97 97
 			$this->array = $value;
98 98
 
99 99
 			return $this;
@@ -102,13 +102,13 @@  discard block
 block discarded – undo
102 102
 		$array = &$this->array;
103 103
 		$keys = explode('.', $dotKey);
104 104
 
105
-		while(count($keys) > 1){
105
+		while (count($keys) > 1) {
106 106
 			$dotKey = array_shift($keys);
107 107
 
108 108
 			// If the key doesn't exist at this depth, we will just create an empty array
109 109
 			// to hold the next value, allowing us to create the arrays to hold final
110 110
 			// values at the correct depth. Then we'll keep digging into the array.
111
-			if(!isset($array[$dotKey]) || !is_array($array[$dotKey])){
111
+			if (!isset($array[$dotKey]) || !is_array($array[$dotKey])) {
112 112
 				$array[$dotKey] = [];
113 113
 			}
114 114
 
Please login to merge, or discard this patch.
src/ArrayHelpers/ByteArray.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/EnumerableInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 
13 13
 namespace chillerlan\Traits;
14 14
 
15
-interface EnumerableInterface{
15
+interface EnumerableInterface {
16 16
 
17 17
 	/**
18 18
 	 * @return array
Please login to merge, or discard this patch.
src/ClassLoader.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -33,8 +33,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Enumerable.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
@@ -90,21 +90,21 @@  discard block
 block discarded – undo
90 90
 	/**
91 91
 	 * @return mixed
92 92
 	 */
93
-	public function __first(){
93
+	public function __first() {
94 94
 		return $this->array[0] ?? null;
95 95
 	}
96 96
 
97 97
 	/**
98 98
 	 * @return mixed
99 99
 	 */
100
-	public function __last(){
100
+	public function __last() {
101 101
 		return $this->array[count($this->array) - 1] ?? null;
102 102
 	}
103 103
 
104 104
 	/**
105 105
 	 * @return $this
106 106
 	 */
107
-	public function __clear(){
107
+	public function __clear() {
108 108
 		$this->array = [];
109 109
 
110 110
 		return $this;
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
 	 */
130 130
 	public function __findAll($callback):array{
131 131
 
132
-		if(!is_callable($callback)){
132
+		if (!is_callable($callback)) {
133 133
 			throw new TraitException('invalid callback');
134 134
 		}
135 135
 
136 136
 		$return = [];
137 137
 
138
-		foreach($this->array as $index => $element){
138
+		foreach ($this->array as $index => $element) {
139 139
 
140
-			if(call_user_func_array($callback, [$element, $index]) === true){
140
+			if (call_user_func_array($callback, [$element, $index]) === true) {
141 141
 				$return[] = $element;
142 142
 			}
143 143
 
@@ -156,15 +156,15 @@  discard block
 block discarded – undo
156 156
 	 */
157 157
 	public function __reject($callback):array{
158 158
 
159
-		if(!is_callable($callback)){
159
+		if (!is_callable($callback)) {
160 160
 			throw new TraitException('invalid callback');
161 161
 		}
162 162
 
163 163
 		$return = [];
164 164
 
165
-		foreach($this->array as $index => $element){
165
+		foreach ($this->array as $index => $element) {
166 166
 
167
-			if(call_user_func_array($callback, [$element, $index]) !== true){
167
+			if (call_user_func_array($callback, [$element, $index]) !== true) {
168 168
 				$return[] = $element;
169 169
 			}
170 170
 
Please login to merge, or discard this patch.
src/Interfaces/ArrayAccessTrait.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.