@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | * |
| 28 | 28 | * @param string $type |
| 29 | 29 | */ |
| 30 | - public function __construct( $type ) { |
|
| 31 | - $this->type = $this->determine( $type ); |
|
| 30 | + public function __construct($type) { |
|
| 31 | + $this->type = $this->determine($type); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | * @return bool |
| 47 | 47 | */ |
| 48 | 48 | public function is_model() { |
| 49 | - if ( ! class_exists( $this->type ) ) { |
|
| 49 | + if (!class_exists($this->type)) { |
|
| 50 | 50 | return false; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - $reflection = new ReflectionClass( $this->type ); |
|
| 54 | - return $reflection->isSubclassOf( 'Intraxia\Jaxion\Axolotl\Model' ); |
|
| 53 | + $reflection = new ReflectionClass($this->type); |
|
| 54 | + return $reflection->isSubclassOf('Intraxia\Jaxion\Axolotl\Model'); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return Model |
| 63 | 63 | */ |
| 64 | - public function create_model( array $data ) { |
|
| 65 | - return new $this->type( $data ); |
|
| 64 | + public function create_model(array $data) { |
|
| 65 | + return new $this->type($data); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @throws InvalidArgumentException |
| 74 | 74 | */ |
| 75 | - public function validate_elements( array $elements ) { |
|
| 76 | - foreach ( $elements as $element ) { |
|
| 77 | - $this->validate_element( $element ); |
|
| 75 | + public function validate_elements(array $elements) { |
|
| 76 | + foreach ($elements as $element) { |
|
| 77 | + $this->validate_element($element); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
@@ -85,25 +85,25 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @throws InvalidArgumentException |
| 87 | 87 | */ |
| 88 | - public function validate_element( $element ) { |
|
| 89 | - $type = gettype( $element ); |
|
| 88 | + public function validate_element($element) { |
|
| 89 | + $type = gettype($element); |
|
| 90 | 90 | $callable = $this->type === 'callable'; |
| 91 | 91 | $is_object = 'object' === $type; |
| 92 | 92 | $loose_check = $this->type === 'object'; |
| 93 | 93 | |
| 94 | 94 | // callable must be callable |
| 95 | - if ( $callable && ! is_callable( $element ) ) { |
|
| 96 | - throw new InvalidArgumentException( 'Item must be callable' ); |
|
| 95 | + if ($callable && !is_callable($element)) { |
|
| 96 | + throw new InvalidArgumentException('Item must be callable'); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // target isn't callable, object must be an instance of target |
| 100 | - if ( ! $loose_check && ! $callable && $is_object && ! is_a( $element, $this->type ) ) { |
|
| 101 | - throw new InvalidArgumentException( "Item is not type or subtype of $this->type" ); |
|
| 100 | + if (!$loose_check && !$callable && $is_object && !is_a($element, $this->type)) { |
|
| 101 | + throw new InvalidArgumentException("Item is not type or subtype of $this->type"); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // a non callable, non object type should match the target string |
| 105 | - if ( ! $callable && ! $is_object && $type !== $this->type ) { |
|
| 106 | - throw new InvalidArgumentException( "Item is not of type: $this->type" ); |
|
| 105 | + if (!$callable && !$is_object && $type !== $this->type) { |
|
| 106 | + throw new InvalidArgumentException("Item is not of type: $this->type"); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
@@ -117,20 +117,20 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @throws InvalidArgumentException |
| 119 | 119 | */ |
| 120 | - private function determine( $type, $key_type = false ) { |
|
| 121 | - if ( ! $key_type && $this->non_scalar_type_exists( $type ) ) { |
|
| 120 | + private function determine($type, $key_type = false) { |
|
| 121 | + if (!$key_type && $this->non_scalar_type_exists($type)) { |
|
| 122 | 122 | return $type; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if ( $scalar_type = $this->determine_scalar( $type ) ) { |
|
| 126 | - if ( $key_type && (in_array( $scalar_type, [ 'double', 'boolean' ] )) ) { |
|
| 127 | - throw new InvalidArgumentException( 'This type is not supported as a key.' ); |
|
| 125 | + if ($scalar_type = $this->determine_scalar($type)) { |
|
| 126 | + if ($key_type && (in_array($scalar_type, ['double', 'boolean']))) { |
|
| 127 | + throw new InvalidArgumentException('This type is not supported as a key.'); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | return $scalar_type; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - throw new InvalidArgumentException( 'This type does not exist.' ); |
|
| 133 | + throw new InvalidArgumentException('This type does not exist.'); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -140,10 +140,10 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @return bool |
| 142 | 142 | */ |
| 143 | - private function non_scalar_type_exists( $type ) { |
|
| 144 | - return class_exists( $type ) |
|
| 145 | - || interface_exists( $type ) |
|
| 146 | - || in_array( $type, [ 'array', 'object', 'callable' ] ); |
|
| 143 | + private function non_scalar_type_exists($type) { |
|
| 144 | + return class_exists($type) |
|
| 145 | + || interface_exists($type) |
|
| 146 | + || in_array($type, ['array', 'object', 'callable']); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -153,19 +153,18 @@ discard block |
||
| 153 | 153 | * |
| 154 | 154 | * @return string|null |
| 155 | 155 | */ |
| 156 | - private function determine_scalar( $type ) { |
|
| 156 | + private function determine_scalar($type) { |
|
| 157 | 157 | $synonyms = array( |
| 158 | 158 | 'int' => 'integer', |
| 159 | 159 | 'float' => 'double', |
| 160 | 160 | 'bool' => 'boolean', |
| 161 | 161 | ); |
| 162 | 162 | |
| 163 | - if ( array_key_exists( $type, $synonyms ) ) { |
|
| 164 | - $type = $synonyms[ $type ]; |
|
| 163 | + if (array_key_exists($type, $synonyms)) { |
|
| 164 | + $type = $synonyms[$type]; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - return in_array( $type, array( 'string', 'integer', 'double', 'boolean' ) ) ? |
|
| 168 | - $type : |
|
| 169 | - null; |
|
| 167 | + return in_array($type, array('string', 'integer', 'double', 'boolean')) ? |
|
| 168 | + $type : null; |
|
| 170 | 169 | } |
| 171 | 170 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @return Collection |
| 24 | 24 | * @throws InvalidArgumentException |
| 25 | 25 | */ |
| 26 | - public function add( $element ); |
|
| 26 | + public function add($element); |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Removes every element from the collection. |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param callable $condition |
| 40 | 40 | * @return bool |
| 41 | 41 | */ |
| 42 | - public function contains( callable $condition ); |
|
| 42 | + public function contains(callable $condition); |
|
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * Returns the first element in the collection that satisfies |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @param callable $condition |
| 49 | 49 | * @return mixed |
| 50 | 50 | */ |
| 51 | - public function find( callable $condition ); |
|
| 51 | + public function find(callable $condition); |
|
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * Returns the index of the first element in the collection that satisfies |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param callable $condition |
| 58 | 58 | * @return int |
| 59 | 59 | */ |
| 60 | - public function find_index( callable $condition ); |
|
| 60 | + public function find_index(callable $condition); |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * Returns the element in the collection at $index. |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @return mixed |
| 67 | 67 | * @throws OutOfRangeException |
| 68 | 68 | */ |
| 69 | - public function at( $index ); |
|
| 69 | + public function at($index); |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * Returns true if $index is within the collection's range and returns false |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @return bool |
| 77 | 77 | * @throws InvalidArgumentException |
| 78 | 78 | */ |
| 79 | - public function index_exists( $index ); |
|
| 79 | + public function index_exists($index); |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * Returns the number of elements in the collection. |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @param callable $condition |
| 93 | 93 | * @return Collection |
| 94 | 94 | */ |
| 95 | - public function filter( callable $condition ); |
|
| 95 | + public function filter(callable $condition); |
|
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | 98 | * Returns the last element in the collection that satisfies $condition, |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param callable $condition |
| 102 | 102 | * @return mixed |
| 103 | 103 | */ |
| 104 | - public function find_last( callable $condition ); |
|
| 104 | + public function find_last(callable $condition); |
|
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | 107 | * Returns the index of the last element in the collection that satisfies |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param callable $condition |
| 111 | 111 | * @return int |
| 112 | 112 | */ |
| 113 | - public function find_last_index( callable $condition ); |
|
| 113 | + public function find_last_index(callable $condition); |
|
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | 116 | * Returns a collection that contains the subset of elements ranging from the |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @return Collection |
| 122 | 122 | * @throws InvalidArgumentException |
| 123 | 123 | */ |
| 124 | - public function slice( $start, $end ); |
|
| 124 | + public function slice($start, $end); |
|
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | 127 | * Inserts $element at $index. |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @throws InvalidArgumentException |
| 133 | 133 | * @throws OutOfRangeException |
| 134 | 134 | */ |
| 135 | - public function insert( $index, $element ); |
|
| 135 | + public function insert($index, $element); |
|
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * Inserts the range $elements at $index. |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @return Collection |
| 143 | 143 | * @throws OutOfRangeException |
| 144 | 144 | */ |
| 145 | - public function insert_range( $index, array $elements ); |
|
| 145 | + public function insert_range($index, array $elements); |
|
| 146 | 146 | |
| 147 | 147 | /** |
| 148 | 148 | * Removes all of the elements that satisfy $condition. |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param callable $condition |
| 151 | 151 | * @return Collection |
| 152 | 152 | */ |
| 153 | - public function without( callable $condition ); |
|
| 153 | + public function without(callable $condition); |
|
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | 156 | * Removes the element at $index. |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @return Collection |
| 160 | 160 | * @throws OutOfRangeException |
| 161 | 161 | */ |
| 162 | - public function remove_at( $index ); |
|
| 162 | + public function remove_at($index); |
|
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | 165 | * Reverses the order of the elements in the collection. |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * @param callable $callback |
| 176 | 176 | * @return Collection |
| 177 | 177 | */ |
| 178 | - public function sort( callable $callback ); |
|
| 178 | + public function sort(callable $callback); |
|
| 179 | 179 | |
| 180 | 180 | /** |
| 181 | 181 | * Returns an array containing the elements in the collection. |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * @param null $initial |
| 193 | 193 | * @return mixed |
| 194 | 194 | */ |
| 195 | - public function reduce( callable $callable, $initial = null ); |
|
| 195 | + public function reduce(callable $callable, $initial = null); |
|
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Returns true if every element in the collection satisfies $condition, |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param callable $condition |
| 202 | 202 | * @return bool |
| 203 | 203 | */ |
| 204 | - public function every( callable $condition ); |
|
| 204 | + public function every(callable $condition); |
|
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | 207 | * Removes all of the elements in the collection starting at index $num. |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | * @return Collection |
| 211 | 211 | * @throws InvalidArgumentException |
| 212 | 212 | */ |
| 213 | - public function drop( $num ); |
|
| 213 | + public function drop($num); |
|
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | 216 | * Removes all of the elements in the collectioin between index 0 and $num. |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * @return Collection |
| 220 | 220 | * @throws InvalidArgumentException |
| 221 | 221 | */ |
| 222 | - public function drop_right( $num ); |
|
| 222 | + public function drop_right($num); |
|
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | 225 | * Iteratively drops elements in the collection that satisfy $condition until |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | * @param callable $condition |
| 229 | 229 | * @return Collection |
| 230 | 230 | */ |
| 231 | - public function drop_while( callable $condition ); |
|
| 231 | + public function drop_while(callable $condition); |
|
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | 234 | * Removes the first element in the collection. |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * @return Collection |
| 246 | 246 | * @throws InvalidArgumentException |
| 247 | 247 | */ |
| 248 | - public function take( $num ); |
|
| 248 | + public function take($num); |
|
| 249 | 249 | |
| 250 | 250 | /** |
| 251 | 251 | * Removes all of the elements in the collection before index $num. |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | * @return Collection |
| 255 | 255 | * @throws InvalidArgumentException |
| 256 | 256 | */ |
| 257 | - public function take_right( $num ); |
|
| 257 | + public function take_right($num); |
|
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | 260 | * Iterates through the collection until an element is encountered that does |
@@ -264,14 +264,14 @@ discard block |
||
| 264 | 264 | * @param callable $condition |
| 265 | 265 | * @return Collection |
| 266 | 266 | */ |
| 267 | - public function take_while( callable $condition ); |
|
| 267 | + public function take_while(callable $condition); |
|
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | 270 | * Applies the callback function $callable to each element in the collection. |
| 271 | 271 | * |
| 272 | 272 | * @param callable $callable |
| 273 | 273 | */ |
| 274 | - public function each( callable $callable ); |
|
| 274 | + public function each(callable $callable); |
|
| 275 | 275 | |
| 276 | 276 | /** |
| 277 | 277 | * Returns a new instance of the collection with the callback function |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * @param callable $callable |
| 281 | 281 | * @return Collection |
| 282 | 282 | */ |
| 283 | - public function map( callable $callable ); |
|
| 283 | + public function map(callable $callable); |
|
| 284 | 284 | |
| 285 | 285 | /** |
| 286 | 286 | * Iteratively reduces the collection to a single value using the callback |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @param null $initial |
| 291 | 291 | * @return mixed |
| 292 | 292 | */ |
| 293 | - public function reduce_right( callable $callable, $initial = null ); |
|
| 293 | + public function reduce_right(callable $callable, $initial = null); |
|
| 294 | 294 | |
| 295 | 295 | /** |
| 296 | 296 | * Randomly reorders the elements in the collection. |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * @return Collection |
| 307 | 307 | * @throws InvalidArgumentException |
| 308 | 308 | */ |
| 309 | - public function merge( $elements ); |
|
| 309 | + public function merge($elements); |
|
| 310 | 310 | |
| 311 | 311 | /** |
| 312 | 312 | * Get first element of the collection |