@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * @param array|\Iterator|\IteratorAggregate|Enumerable $source Source sequence. |
| 14 | 14 | * @throws \InvalidArgumentException If source is not array or Traversible or Enumerable. |
| 15 | 15 | * @throws \UnexpectedValueException If source contains no elements (checked during enumeration). |
| 16 | - * @return Enumerable Endless list of items repeating the source sequence. |
|
| 16 | + * @return EnumerableGeneration Endless list of items repeating the source sequence. |
|
| 17 | 17 | * @package YaLinqo\Generation |
| 18 | 18 | */ |
| 19 | 19 | public static function cycle ($source) |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | /** |
| 37 | 37 | * Returns an empty sequence. |
| 38 | 38 | * <p><b>Syntax</b>: emptyEnum () |
| 39 | - * @return Enumerable |
|
| 39 | + * @return EnumerableGeneration |
|
| 40 | 40 | * @package YaLinqo\Generation |
| 41 | 41 | */ |
| 42 | 42 | public static function emptyEnum () |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param mixed $seedValue Initial state of the generator loop for values. Default: null. |
| 85 | 85 | * @param callable|null $funcKey {(v, k) ==> key} State update function to run on key after every iteration of the generator loop. Default: increment. |
| 86 | 86 | * @param mixed $seedKey Initial state of the generator loop ofr keys. Default: 0. |
| 87 | - * @return Enumerable |
|
| 87 | + * @return EnumerableGeneration |
|
| 88 | 88 | * @package YaLinqo\Generation |
| 89 | 89 | */ |
| 90 | 90 | public static function generate ($funcValue, $seedValue = null, $funcKey = null, $seedKey = null) |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * <p><b>Syntax</b>: toInfinity ([start [, step]]) |
| 112 | 112 | * @param int $start The first integer in the sequence. Default: 0. |
| 113 | 113 | * @param int $step The difference between adjacent integers. Default: 1. |
| 114 | - * @return Enumerable |
|
| 114 | + * @return EnumerableGeneration |
|
| 115 | 115 | * @package YaLinqo\Generation |
| 116 | 116 | */ |
| 117 | 117 | public static function toInfinity ($start = 0, $step = 1) |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * @param string $subject The input string. |
| 130 | 130 | * @param string $pattern The pattern to search for, as a string. |
| 131 | 131 | * @param int $flags Can be a combination of the following flags: PREG_PATTERN_ORDER, PREG_SET_ORDER, PREG_OFFSET_CAPTURE. Default: PREG_SET_ORDER. |
| 132 | - * @return Enumerable |
|
| 132 | + * @return EnumerableGeneration |
|
| 133 | 133 | * @see preg_match_all |
| 134 | 134 | * @package YaLinqo\Generation |
| 135 | 135 | */ |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * <p><b>Syntax</b>: toNegativeInfinity ([start [, step]]) |
| 147 | 147 | * @param int $start The first integer in the sequence. Default: 0. |
| 148 | 148 | * @param int $step The difference between adjacent integers. Default: 1. |
| 149 | - * @return Enumerable |
|
| 149 | + * @return EnumerableGeneration |
|
| 150 | 150 | * @package YaLinqo\Generation |
| 151 | 151 | */ |
| 152 | 152 | public static function toNegativeInfinity ($start = 0, $step = 1) |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * Returns a sequence that contains a single element with a specified value. |
| 159 | 159 | * <p><b>Syntax</b>: returnEnum (element) |
| 160 | 160 | * @param mixed $element The single element in the resulting sequence. |
| 161 | - * @return Enumerable Observable sequence containing the single specified element. |
|
| 161 | + * @return EnumerableGeneration Observable sequence containing the single specified element. |
|
| 162 | 162 | * @package YaLinqo\Generation |
| 163 | 163 | */ |
| 164 | 164 | public static function returnEnum ($element) |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @param int $start The value of the first integer in the sequence. |
| 175 | 175 | * @param int $count The number of integers to generate. |
| 176 | 176 | * @param int $step The difference between adjacent integers. Default: 1. |
| 177 | - * @return Enumerable A sequence that contains a range of integral numbers. |
|
| 177 | + * @return EnumerableGeneration A sequence that contains a range of integral numbers. |
|
| 178 | 178 | * @package YaLinqo\Generation |
| 179 | 179 | */ |
| 180 | 180 | public static function range ($start, $count, $step = 1) |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * @param int $start The value of the first integer in the sequence. |
| 197 | 197 | * @param int $count The number of integers to generate. |
| 198 | 198 | * @param int $step The difference between adjacent integers. Default: 1. |
| 199 | - * @return Enumerable A sequence that contains a range of integral numbers. |
|
| 199 | + * @return EnumerableGeneration A sequence that contains a range of integral numbers. |
|
| 200 | 200 | * @package YaLinqo\Generation |
| 201 | 201 | */ |
| 202 | 202 | public static function rangeDown ($start, $count, $step = 1) |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * @param int $end The value of the last integer in the sequence (not included). |
| 214 | 214 | * @param int $step The difference between adjacent integers. Default: 1. |
| 215 | 215 | * @throws \InvalidArgumentException If step is not a positive number. |
| 216 | - * @return Enumerable A sequence that contains a range of integral numbers. |
|
| 216 | + * @return EnumerableGeneration A sequence that contains a range of integral numbers. |
|
| 217 | 217 | * @package YaLinqo\Generation |
| 218 | 218 | */ |
| 219 | 219 | public static function rangeTo ($start, $end, $step = 1) |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * @param int $element The value to be repeated. |
| 243 | 243 | * @param int $count The number of times to repeat the value in the generated sequence. Default: null. |
| 244 | 244 | * @throws \InvalidArgumentException If count is less than 0. |
| 245 | - * @return Enumerable A sequence that contains a repeated value. |
|
| 245 | + * @return EnumerableGeneration A sequence that contains a repeated value. |
|
| 246 | 246 | * @package YaLinqo\Generation |
| 247 | 247 | */ |
| 248 | 248 | public static function repeat ($element, $count = null) |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | * @param string $subject The input string. |
| 262 | 262 | * @param string $pattern The pattern to search for, as a string. |
| 263 | 263 | * @param int $flags flags can be any combination of the following flags: PREG_SPLIT_NO_EMPTY, PREG_SPLIT_DELIM_CAPTURE, PREG_SPLIT_OFFSET_CAPTURE. Default: 0. |
| 264 | - * @return Enumerable |
|
| 264 | + * @return EnumerableGeneration |
|
| 265 | 265 | * @see preg_split |
| 266 | 266 | * @package YaLinqo\Generation |
| 267 | 267 | */ |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | * @return Enumerable Endless list of items repeating the source sequence. |
| 17 | 17 | * @package YaLinqo\Generation |
| 18 | 18 | */ |
| 19 | - public static function cycle ($source) |
|
| 19 | + public static function cycle($source) |
|
| 20 | 20 | { |
| 21 | 21 | $source = self::from($source); |
| 22 | 22 | |
| 23 | - return new self(function () use ($source) { |
|
| 23 | + return new self(function() use ($source) { |
|
| 24 | 24 | $isEmpty = true; |
| 25 | 25 | while (true) { |
| 26 | 26 | foreach ($source as $v) { |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @return Enumerable |
| 40 | 40 | * @package YaLinqo\Generation |
| 41 | 41 | */ |
| 42 | - public static function emptyEnum () |
|
| 42 | + public static function emptyEnum() |
|
| 43 | 43 | { |
| 44 | 44 | return new self(new \EmptyIterator, false); |
| 45 | 45 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @return Enumerable |
| 60 | 60 | * @package YaLinqo\Generation |
| 61 | 61 | */ |
| 62 | - public static function from ($source) |
|
| 62 | + public static function from($source) |
|
| 63 | 63 | { |
| 64 | 64 | $it = null; |
| 65 | 65 | if ($source instanceof Enumerable) |
@@ -87,12 +87,12 @@ discard block |
||
| 87 | 87 | * @return Enumerable |
| 88 | 88 | * @package YaLinqo\Generation |
| 89 | 89 | */ |
| 90 | - public static function generate ($funcValue, $seedValue = null, $funcKey = null, $seedKey = null) |
|
| 90 | + public static function generate($funcValue, $seedValue = null, $funcKey = null, $seedKey = null) |
|
| 91 | 91 | { |
| 92 | 92 | $funcValue = Utils::createLambda($funcValue, 'v,k'); |
| 93 | 93 | $funcKey = Utils::createLambda($funcKey, 'v,k', false); |
| 94 | 94 | |
| 95 | - return new self(function () use ($funcValue, $funcKey, $seedValue, $seedKey) { |
|
| 95 | + return new self(function() use ($funcValue, $funcKey, $seedValue, $seedKey) { |
|
| 96 | 96 | $key = $seedKey === null ? ($funcKey ? $funcKey($seedValue, $seedKey) : 0) : $seedKey; |
| 97 | 97 | $value = $seedValue === null ? $funcValue($seedValue, $seedKey) : $seedValue; |
| 98 | 98 | yield $key => $value; |
@@ -114,9 +114,9 @@ discard block |
||
| 114 | 114 | * @return Enumerable |
| 115 | 115 | * @package YaLinqo\Generation |
| 116 | 116 | */ |
| 117 | - public static function toInfinity ($start = 0, $step = 1) |
|
| 117 | + public static function toInfinity($start = 0, $step = 1) |
|
| 118 | 118 | { |
| 119 | - return new self(function () use ($start, $step) { |
|
| 119 | + return new self(function() use ($start, $step) { |
|
| 120 | 120 | $value = $start - $step; |
| 121 | 121 | while (true) |
| 122 | 122 | yield $value += $step; |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | * @see preg_match_all |
| 134 | 134 | * @package YaLinqo\Generation |
| 135 | 135 | */ |
| 136 | - public static function matches ($subject, $pattern, $flags = PREG_SET_ORDER) |
|
| 136 | + public static function matches($subject, $pattern, $flags = PREG_SET_ORDER) |
|
| 137 | 137 | { |
| 138 | - return new self(function () use ($subject, $pattern, $flags) { |
|
| 138 | + return new self(function() use ($subject, $pattern, $flags) { |
|
| 139 | 139 | preg_match_all($pattern, $subject, $matches, $flags); |
| 140 | 140 | return $matches !== false ? self::from($matches)->getIterator() : self::emptyEnum(); |
| 141 | 141 | }); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @return Enumerable |
| 150 | 150 | * @package YaLinqo\Generation |
| 151 | 151 | */ |
| 152 | - public static function toNegativeInfinity ($start = 0, $step = 1) |
|
| 152 | + public static function toNegativeInfinity($start = 0, $step = 1) |
|
| 153 | 153 | { |
| 154 | 154 | return self::toInfinity($start, -$step); |
| 155 | 155 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @return Enumerable Observable sequence containing the single specified element. |
| 162 | 162 | * @package YaLinqo\Generation |
| 163 | 163 | */ |
| 164 | - public static function returnEnum ($element) |
|
| 164 | + public static function returnEnum($element) |
|
| 165 | 165 | { |
| 166 | 166 | return self::repeat($element, 1); |
| 167 | 167 | } |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | * @return Enumerable A sequence that contains a range of integral numbers. |
| 178 | 178 | * @package YaLinqo\Generation |
| 179 | 179 | */ |
| 180 | - public static function range ($start, $count, $step = 1) |
|
| 180 | + public static function range($start, $count, $step = 1) |
|
| 181 | 181 | { |
| 182 | 182 | if ($count <= 0) |
| 183 | 183 | return self::emptyEnum(); |
| 184 | - return new self(function () use ($start, $count, $step) { |
|
| 184 | + return new self(function() use ($start, $count, $step) { |
|
| 185 | 185 | $value = $start - $step; |
| 186 | 186 | while ($count-- > 0) |
| 187 | 187 | yield $value += $step; |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @return Enumerable A sequence that contains a range of integral numbers. |
| 200 | 200 | * @package YaLinqo\Generation |
| 201 | 201 | */ |
| 202 | - public static function rangeDown ($start, $count, $step = 1) |
|
| 202 | + public static function rangeDown($start, $count, $step = 1) |
|
| 203 | 203 | { |
| 204 | 204 | return self::range($start, $count, -$step); |
| 205 | 205 | } |
@@ -216,11 +216,11 @@ discard block |
||
| 216 | 216 | * @return Enumerable A sequence that contains a range of integral numbers. |
| 217 | 217 | * @package YaLinqo\Generation |
| 218 | 218 | */ |
| 219 | - public static function rangeTo ($start, $end, $step = 1) |
|
| 219 | + public static function rangeTo($start, $end, $step = 1) |
|
| 220 | 220 | { |
| 221 | 221 | if ($step <= 0) |
| 222 | 222 | throw new \InvalidArgumentException(Errors::STEP_NEGATIVE); |
| 223 | - return new self(function () use ($start, $end, $step) { |
|
| 223 | + return new self(function() use ($start, $end, $step) { |
|
| 224 | 224 | if ($start <= $end) { |
| 225 | 225 | for ($i = $start; $i < $end; $i += $step) |
| 226 | 226 | yield $i; |
@@ -245,11 +245,11 @@ discard block |
||
| 245 | 245 | * @return Enumerable A sequence that contains a repeated value. |
| 246 | 246 | * @package YaLinqo\Generation |
| 247 | 247 | */ |
| 248 | - public static function repeat ($element, $count = null) |
|
| 248 | + public static function repeat($element, $count = null) |
|
| 249 | 249 | { |
| 250 | 250 | if ($count < 0) |
| 251 | 251 | throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO); |
| 252 | - return new self(function () use ($element, $count) { |
|
| 252 | + return new self(function() use ($element, $count) { |
|
| 253 | 253 | for ($i = 0; $i < $count || $count === null; $i++) |
| 254 | 254 | yield $element; |
| 255 | 255 | }); |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @see preg_split |
| 266 | 266 | * @package YaLinqo\Generation |
| 267 | 267 | */ |
| 268 | - public static function split ($subject, $pattern, $flags = 0) |
|
| 268 | + public static function split($subject, $pattern, $flags = 0) |
|
| 269 | 269 | { |
| 270 | 270 | return new self( |
| 271 | 271 | new \ArrayIterator(preg_split($pattern, $subject, -1, $flags)), |
@@ -27,8 +27,9 @@ discard block |
||
| 27 | 27 | yield $v; |
| 28 | 28 | $isEmpty = false; |
| 29 | 29 | } |
| 30 | - if ($isEmpty) |
|
| 31 | - throw new \UnexpectedValueException(Errors::NO_ELEMENTS); |
|
| 30 | + if ($isEmpty) { |
|
| 31 | + throw new \UnexpectedValueException(Errors::NO_ELEMENTS); |
|
| 32 | + } |
|
| 32 | 33 | } |
| 33 | 34 | }); |
| 34 | 35 | } |
@@ -63,14 +64,15 @@ discard block |
||
| 63 | 64 | public static function from ($source) |
| 64 | 65 | { |
| 65 | 66 | $it = null; |
| 66 | - if ($source instanceof Enumerable) |
|
| 67 | - return $source; |
|
| 68 | - else if (is_array($source)) |
|
| 69 | - $it = new \ArrayIterator($source); |
|
| 70 | - elseif ($source instanceof \IteratorAggregate) |
|
| 71 | - $it = $source->getIterator(); |
|
| 72 | - elseif ($source instanceof \Traversable) |
|
| 73 | - $it = $source; |
|
| 67 | + if ($source instanceof Enumerable) { |
|
| 68 | + return $source; |
|
| 69 | + } else if (is_array($source)) { |
|
| 70 | + $it = new \ArrayIterator($source); |
|
| 71 | + } elseif ($source instanceof \IteratorAggregate) { |
|
| 72 | + $it = $source->getIterator(); |
|
| 73 | + } elseif ($source instanceof \Traversable) { |
|
| 74 | + $it = $source; |
|
| 75 | + } |
|
| 74 | 76 | if ($it !== null) { |
| 75 | 77 | return new self($it, false); |
| 76 | 78 | } |
@@ -119,8 +121,9 @@ discard block |
||
| 119 | 121 | { |
| 120 | 122 | return new self(function () use ($start, $step) { |
| 121 | 123 | $value = $start - $step; |
| 122 | - while (true) |
|
| 123 | - yield $value += $step; |
|
| 124 | + while (true) { |
|
| 125 | + yield $value += $step; |
|
| 126 | + } |
|
| 124 | 127 | }); |
| 125 | 128 | } |
| 126 | 129 | |
@@ -180,12 +183,14 @@ discard block |
||
| 180 | 183 | */ |
| 181 | 184 | public static function range ($start, $count, $step = 1) |
| 182 | 185 | { |
| 183 | - if ($count <= 0) |
|
| 184 | - return self::emptyEnum(); |
|
| 186 | + if ($count <= 0) { |
|
| 187 | + return self::emptyEnum(); |
|
| 188 | + } |
|
| 185 | 189 | return new self(function () use ($start, $count, $step) { |
| 186 | 190 | $value = $start - $step; |
| 187 | - while ($count-- > 0) |
|
| 188 | - yield $value += $step; |
|
| 191 | + while ($count-- > 0) { |
|
| 192 | + yield $value += $step; |
|
| 193 | + } |
|
| 189 | 194 | }); |
| 190 | 195 | } |
| 191 | 196 | |
@@ -219,16 +224,18 @@ discard block |
||
| 219 | 224 | */ |
| 220 | 225 | public static function rangeTo ($start, $end, $step = 1) |
| 221 | 226 | { |
| 222 | - if ($step <= 0) |
|
| 223 | - throw new \InvalidArgumentException(Errors::STEP_NEGATIVE); |
|
| 227 | + if ($step <= 0) { |
|
| 228 | + throw new \InvalidArgumentException(Errors::STEP_NEGATIVE); |
|
| 229 | + } |
|
| 224 | 230 | return new self(function () use ($start, $end, $step) { |
| 225 | 231 | if ($start <= $end) { |
| 226 | - for ($i = $start; $i < $end; $i += $step) |
|
| 227 | - yield $i; |
|
| 228 | - } |
|
| 229 | - else { |
|
| 230 | - for ($i = $start; $i > $end; $i -= $step) |
|
| 231 | - yield $i; |
|
| 232 | + for ($i = $start; $i < $end; $i += $step) { |
|
| 233 | + yield $i; |
|
| 234 | + } |
|
| 235 | + } else { |
|
| 236 | + for ($i = $start; $i > $end; $i -= $step) { |
|
| 237 | + yield $i; |
|
| 238 | + } |
|
| 232 | 239 | } |
| 233 | 240 | }); |
| 234 | 241 | } |
@@ -248,11 +255,13 @@ discard block |
||
| 248 | 255 | */ |
| 249 | 256 | public static function repeat ($element, $count = null) |
| 250 | 257 | { |
| 251 | - if ($count < 0) |
|
| 252 | - throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO); |
|
| 258 | + if ($count < 0) { |
|
| 259 | + throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO); |
|
| 260 | + } |
|
| 253 | 261 | return new self(function () use ($element, $count) { |
| 254 | - for ($i = 0; $i < $count || $count === null; $i++) |
|
| 255 | - yield $element; |
|
| 262 | + for ($i = 0; $i < $count || $count === null; $i++) { |
|
| 263 | + yield $element; |
|
| 264 | + } |
|
| 256 | 265 | }); |
| 257 | 266 | } |
| 258 | 267 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * @return mixed The value at the key in the source sequence. |
| 18 | 18 | * @package YaLinqo\Pagination |
| 19 | 19 | */ |
| 20 | - public function elementAt ($key) |
|
| 20 | + public function elementAt($key) |
|
| 21 | 21 | { |
| 22 | 22 | /** @var $it \Iterator|\ArrayAccess */ |
| 23 | 23 | $it = $this->getIterator(); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @return mixed default value if the key is not found in the source sequence; otherwise, the value at the specified key in the source sequence. |
| 45 | 45 | * @package YaLinqo\Pagination |
| 46 | 46 | */ |
| 47 | - public function elementAtOrDefault ($key, $default = null) |
|
| 47 | + public function elementAtOrDefault($key, $default = null) |
|
| 48 | 48 | { |
| 49 | 49 | /** @var $it \Iterator|\ArrayAccess */ |
| 50 | 50 | $it = $this->getIterator(); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @return mixed If predicate is null: the first element in the specified sequence. If predicate is not null: The first element in the sequence that passes the test in the specified predicate function. |
| 73 | 73 | * @package YaLinqo\Pagination |
| 74 | 74 | */ |
| 75 | - public function first ($predicate = null) |
|
| 75 | + public function first($predicate = null) |
|
| 76 | 76 | { |
| 77 | 77 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 78 | 78 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @return mixed If predicate is null: default value if source is empty; otherwise, the first element in source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate. |
| 96 | 96 | * @package YaLinqo\Pagination |
| 97 | 97 | */ |
| 98 | - public function firstOrDefault ($default = null, $predicate = null) |
|
| 98 | + public function firstOrDefault($default = null, $predicate = null) |
|
| 99 | 99 | { |
| 100 | 100 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 101 | 101 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @return mixed If predicate is null: the result of calling a fallback function if source is empty; otherwise, the first element in source. If predicate is not null: the result of calling a fallback function if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate. |
| 119 | 119 | * @package YaLinqo\Pagination |
| 120 | 120 | */ |
| 121 | - public function firstOrFallback ($fallback, $predicate = null) |
|
| 121 | + public function firstOrFallback($fallback, $predicate = null) |
|
| 122 | 122 | { |
| 123 | 123 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 124 | 124 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @return mixed If predicate is null: the last element in the specified sequence. If predicate is not null: The last element in the sequence that passes the test in the specified predicate function. |
| 143 | 143 | * @package YaLinqo\Pagination |
| 144 | 144 | */ |
| 145 | - public function last ($predicate = null) |
|
| 145 | + public function last($predicate = null) |
|
| 146 | 146 | { |
| 147 | 147 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 148 | 148 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * @return mixed If predicate is null: default value if source is empty; otherwise, the last element in source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the last element in source that passes the test specified by predicate. |
| 172 | 172 | * @package YaLinqo\Pagination |
| 173 | 173 | */ |
| 174 | - public function lastOrDefault ($default = null, $predicate = null) |
|
| 174 | + public function lastOrDefault($default = null, $predicate = null) |
|
| 175 | 175 | { |
| 176 | 176 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 177 | 177 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @return mixed If predicate is null: the result of calling a fallback function if source is empty; otherwise, the last element in source. If predicate is not null: the result of calling a fallback function if source is empty or if no element passes the test specified by predicate; otherwise, the last element in source that passes the test specified by predicate. |
| 199 | 199 | * @package YaLinqo\Pagination |
| 200 | 200 | */ |
| 201 | - public function lastOrFallback ($fallback, $predicate = null) |
|
| 201 | + public function lastOrFallback($fallback, $predicate = null) |
|
| 202 | 202 | { |
| 203 | 203 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 204 | 204 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @return mixed If predicate is null: the single element of the input sequence. If predicate is not null: The single element of the sequence that passes the test in the specified predicate function. |
| 227 | 227 | * @package YaLinqo\Pagination |
| 228 | 228 | */ |
| 229 | - public function single ($predicate = null) |
|
| 229 | + public function single($predicate = null) |
|
| 230 | 230 | { |
| 231 | 231 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 232 | 232 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return mixed If predicate is null: default value if source is empty; otherwise, the single element of the source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the single element of the source that passes the test specified by predicate. |
| 259 | 259 | * @package YaLinqo\Pagination |
| 260 | 260 | */ |
| 261 | - public function singleOrDefault ($default = null, $predicate = null) |
|
| 261 | + public function singleOrDefault($default = null, $predicate = null) |
|
| 262 | 262 | { |
| 263 | 263 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 264 | 264 | |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @return mixed If predicate is null: the result of calling a fallback function if source is empty; otherwise, the single element of the source. If predicate is not null: the result of calling a fallback function if source is empty or if no element passes the test specified by predicate; otherwise, the single element of the source that passes the test specified by predicate. |
| 289 | 289 | * @package YaLinqo\Pagination |
| 290 | 290 | */ |
| 291 | - public function singleOrFallback ($fallback, $predicate = null) |
|
| 291 | + public function singleOrFallback($fallback, $predicate = null) |
|
| 292 | 292 | { |
| 293 | 293 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 294 | 294 | |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | * @return mixed The key of the first occurrence of value, if found; otherwise, null. |
| 314 | 314 | * @package YaLinqo\Pagination |
| 315 | 315 | */ |
| 316 | - public function indexOf ($value) |
|
| 316 | + public function indexOf($value) |
|
| 317 | 317 | { |
| 318 | 318 | foreach ($this as $k => $v) { |
| 319 | 319 | if ($v === $value) |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | * @return mixed The key of the last occurrence of value, if found; otherwise, null. |
| 331 | 331 | * @package YaLinqo\Pagination |
| 332 | 332 | */ |
| 333 | - public function lastIndexOf ($value) |
|
| 333 | + public function lastIndexOf($value) |
|
| 334 | 334 | { |
| 335 | 335 | $key = null; |
| 336 | 336 | foreach ($this as $k => $v) { |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | * @return mixed The key of the first occurrence of an element that matches the conditions defined by predicate, if found; otherwise, null. |
| 349 | 349 | * @package YaLinqo\Pagination |
| 350 | 350 | */ |
| 351 | - public function findIndex ($predicate) |
|
| 351 | + public function findIndex($predicate) |
|
| 352 | 352 | { |
| 353 | 353 | $predicate = Utils::createLambda($predicate, 'v,k'); |
| 354 | 354 | |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | * @return mixed The key of the last occurrence of an element that matches the conditions defined by predicate, if found; otherwise, null. |
| 368 | 368 | * @package YaLinqo\Pagination |
| 369 | 369 | */ |
| 370 | - public function findLastIndex ($predicate) |
|
| 370 | + public function findLastIndex($predicate) |
|
| 371 | 371 | { |
| 372 | 372 | $predicate = Utils::createLambda($predicate, 'v,k'); |
| 373 | 373 | |
@@ -388,9 +388,9 @@ discard block |
||
| 388 | 388 | * @return Enumerable A sequence that contains the elements that occur after the specified index in the input sequence. |
| 389 | 389 | * @package YaLinqo\Pagination |
| 390 | 390 | */ |
| 391 | - public function skip ($count) |
|
| 391 | + public function skip($count) |
|
| 392 | 392 | { |
| 393 | - return new self(function () use ($count) { |
|
| 393 | + return new self(function() use ($count) { |
|
| 394 | 394 | $it = $this->getIterator(); |
| 395 | 395 | $it->rewind(); |
| 396 | 396 | for ($i = 0; $i < $count && $it->valid(); ++$i) |
@@ -411,11 +411,11 @@ discard block |
||
| 411 | 411 | * @return Enumerable A sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate. |
| 412 | 412 | * @package YaLinqo\Pagination |
| 413 | 413 | */ |
| 414 | - public function skipWhile ($predicate) |
|
| 414 | + public function skipWhile($predicate) |
|
| 415 | 415 | { |
| 416 | 416 | $predicate = Utils::createLambda($predicate, 'v,k'); |
| 417 | 417 | |
| 418 | - return new self(function () use ($predicate) { |
|
| 418 | + return new self(function() use ($predicate) { |
|
| 419 | 419 | $yielding = false; |
| 420 | 420 | foreach ($this as $k => $v) { |
| 421 | 421 | if (!$yielding && !$predicate($v, $k)) |
@@ -435,12 +435,12 @@ discard block |
||
| 435 | 435 | * @return Enumerable A sequence that contains the specified number of elements from the start of the input sequence. |
| 436 | 436 | * @package YaLinqo\Pagination |
| 437 | 437 | */ |
| 438 | - public function take ($count) |
|
| 438 | + public function take($count) |
|
| 439 | 439 | { |
| 440 | 440 | if ($count <= 0) |
| 441 | 441 | return new self(new \EmptyIterator, false); |
| 442 | 442 | |
| 443 | - return new self(function () use ($count) { |
|
| 443 | + return new self(function() use ($count) { |
|
| 444 | 444 | foreach ($this as $k => $v) { |
| 445 | 445 | yield $k => $v; |
| 446 | 446 | if (--$count == 0) |
@@ -458,11 +458,11 @@ discard block |
||
| 458 | 458 | * @return Enumerable A sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes. |
| 459 | 459 | * @package YaLinqo\Pagination |
| 460 | 460 | */ |
| 461 | - public function takeWhile ($predicate) |
|
| 461 | + public function takeWhile($predicate) |
|
| 462 | 462 | { |
| 463 | 463 | $predicate = Utils::createLambda($predicate, 'v,k'); |
| 464 | 464 | |
| 465 | - return new self(function () use ($predicate) { |
|
| 465 | + return new self(function() use ($predicate) { |
|
| 466 | 466 | foreach ($this as $k => $v) { |
| 467 | 467 | if (!$predicate($v, $k)) |
| 468 | 468 | break; |
@@ -474,5 +474,5 @@ discard block |
||
| 474 | 474 | /** |
| 475 | 475 | * @return \Iterator |
| 476 | 476 | */ |
| 477 | - public abstract function getIterator (); |
|
| 477 | + public abstract function getIterator(); |
|
| 478 | 478 | } |
| 479 | 479 | \ No newline at end of file |
@@ -23,14 +23,16 @@ discard block |
||
| 23 | 23 | $it = $this->getIterator(); |
| 24 | 24 | |
| 25 | 25 | if ($it instanceof \ArrayAccess) { |
| 26 | - if (!$it->offsetExists($key)) |
|
| 27 | - throw new \UnexpectedValueException(Errors::NO_KEY); |
|
| 26 | + if (!$it->offsetExists($key)) { |
|
| 27 | + throw new \UnexpectedValueException(Errors::NO_KEY); |
|
| 28 | + } |
|
| 28 | 29 | return $it->offsetGet($key); |
| 29 | 30 | } |
| 30 | 31 | |
| 31 | 32 | foreach ($it as $k => $v) { |
| 32 | - if ($k === $key) |
|
| 33 | - return $v; |
|
| 33 | + if ($k === $key) { |
|
| 34 | + return $v; |
|
| 35 | + } |
|
| 34 | 36 | } |
| 35 | 37 | throw new \UnexpectedValueException(Errors::NO_KEY); |
| 36 | 38 | } |
@@ -49,12 +51,14 @@ discard block |
||
| 49 | 51 | /** @var $it \Iterator|\ArrayAccess */ |
| 50 | 52 | $it = $this->getIterator(); |
| 51 | 53 | |
| 52 | - if ($it instanceof \ArrayAccess) |
|
| 53 | - return $it->offsetExists($key) ? $it->offsetGet($key) : $default; |
|
| 54 | + if ($it instanceof \ArrayAccess) { |
|
| 55 | + return $it->offsetExists($key) ? $it->offsetGet($key) : $default; |
|
| 56 | + } |
|
| 54 | 57 | |
| 55 | 58 | foreach ($it as $k => $v) { |
| 56 | - if ($k === $key) |
|
| 57 | - return $v; |
|
| 59 | + if ($k === $key) { |
|
| 60 | + return $v; |
|
| 61 | + } |
|
| 58 | 62 | } |
| 59 | 63 | return $default; |
| 60 | 64 | } |
@@ -77,8 +81,9 @@ discard block |
||
| 77 | 81 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 78 | 82 | |
| 79 | 83 | foreach ($this as $k => $v) { |
| 80 | - if ($predicate($v, $k)) |
|
| 81 | - return $v; |
|
| 84 | + if ($predicate($v, $k)) { |
|
| 85 | + return $v; |
|
| 86 | + } |
|
| 82 | 87 | } |
| 83 | 88 | throw new \UnexpectedValueException(Errors::NO_MATCHES); |
| 84 | 89 | } |
@@ -100,8 +105,9 @@ discard block |
||
| 100 | 105 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 101 | 106 | |
| 102 | 107 | foreach ($this as $k => $v) { |
| 103 | - if ($predicate($v, $k)) |
|
| 104 | - return $v; |
|
| 108 | + if ($predicate($v, $k)) { |
|
| 109 | + return $v; |
|
| 110 | + } |
|
| 105 | 111 | } |
| 106 | 112 | return $default; |
| 107 | 113 | } |
@@ -123,8 +129,9 @@ discard block |
||
| 123 | 129 | $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true); |
| 124 | 130 | |
| 125 | 131 | foreach ($this as $k => $v) { |
| 126 | - if ($predicate($v, $k)) |
|
| 127 | - return $v; |
|
| 132 | + if ($predicate($v, $k)) { |
|
| 133 | + return $v; |
|
| 134 | + } |
|
| 128 | 135 | } |
| 129 | 136 | return $fallback(); |
| 130 | 137 | } |
@@ -154,8 +161,9 @@ discard block |
||
| 154 | 161 | $value = $v; |
| 155 | 162 | } |
| 156 | 163 | } |
| 157 | - if (!$found) |
|
| 158 | - throw new \UnexpectedValueException(Errors::NO_MATCHES); |
|
| 164 | + if (!$found) { |
|
| 165 | + throw new \UnexpectedValueException(Errors::NO_MATCHES); |
|
| 166 | + } |
|
| 159 | 167 | return $value; |
| 160 | 168 | } |
| 161 | 169 | |
@@ -234,14 +242,16 @@ discard block |
||
| 234 | 242 | $value = null; |
| 235 | 243 | foreach ($this as $k => $v) { |
| 236 | 244 | if ($predicate($v, $k)) { |
| 237 | - if ($found) |
|
| 238 | - throw new \UnexpectedValueException(Errors::MANY_MATCHES); |
|
| 245 | + if ($found) { |
|
| 246 | + throw new \UnexpectedValueException(Errors::MANY_MATCHES); |
|
| 247 | + } |
|
| 239 | 248 | $found = true; |
| 240 | 249 | $value = $v; |
| 241 | 250 | } |
| 242 | 251 | } |
| 243 | - if (!$found) |
|
| 244 | - throw new \UnexpectedValueException(Errors::NO_MATCHES); |
|
| 252 | + if (!$found) { |
|
| 253 | + throw new \UnexpectedValueException(Errors::NO_MATCHES); |
|
| 254 | + } |
|
| 245 | 255 | return $value; |
| 246 | 256 | } |
| 247 | 257 | |
@@ -266,8 +276,9 @@ discard block |
||
| 266 | 276 | $value = null; |
| 267 | 277 | foreach ($this as $k => $v) { |
| 268 | 278 | if ($predicate($v, $k)) { |
| 269 | - if ($found) |
|
| 270 | - throw new \UnexpectedValueException(Errors::MANY_MATCHES); |
|
| 279 | + if ($found) { |
|
| 280 | + throw new \UnexpectedValueException(Errors::MANY_MATCHES); |
|
| 281 | + } |
|
| 271 | 282 | $found = true; |
| 272 | 283 | $value = $v; |
| 273 | 284 | } |
@@ -296,8 +307,9 @@ discard block |
||
| 296 | 307 | $value = null; |
| 297 | 308 | foreach ($this as $k => $v) { |
| 298 | 309 | if ($predicate($v, $k)) { |
| 299 | - if ($found) |
|
| 300 | - throw new \UnexpectedValueException(Errors::MANY_MATCHES); |
|
| 310 | + if ($found) { |
|
| 311 | + throw new \UnexpectedValueException(Errors::MANY_MATCHES); |
|
| 312 | + } |
|
| 301 | 313 | $found = true; |
| 302 | 314 | $value = $v; |
| 303 | 315 | } |
@@ -316,8 +328,9 @@ discard block |
||
| 316 | 328 | public function indexOf ($value) |
| 317 | 329 | { |
| 318 | 330 | foreach ($this as $k => $v) { |
| 319 | - if ($v === $value) |
|
| 320 | - return $k; |
|
| 331 | + if ($v === $value) { |
|
| 332 | + return $k; |
|
| 333 | + } |
|
| 321 | 334 | } |
| 322 | 335 | return null; // not -1 |
| 323 | 336 | } |
@@ -334,8 +347,9 @@ discard block |
||
| 334 | 347 | { |
| 335 | 348 | $key = null; |
| 336 | 349 | foreach ($this as $k => $v) { |
| 337 | - if ($v === $value) |
|
| 338 | - $key = $k; |
|
| 350 | + if ($v === $value) { |
|
| 351 | + $key = $k; |
|
| 352 | + } |
|
| 339 | 353 | } |
| 340 | 354 | return $key; // not -1 |
| 341 | 355 | } |
@@ -353,8 +367,9 @@ discard block |
||
| 353 | 367 | $predicate = Utils::createLambda($predicate, 'v,k'); |
| 354 | 368 | |
| 355 | 369 | foreach ($this as $k => $v) { |
| 356 | - if ($predicate($v, $k)) |
|
| 357 | - return $k; |
|
| 370 | + if ($predicate($v, $k)) { |
|
| 371 | + return $k; |
|
| 372 | + } |
|
| 358 | 373 | } |
| 359 | 374 | return null; // not -1 |
| 360 | 375 | } |
@@ -373,8 +388,9 @@ discard block |
||
| 373 | 388 | |
| 374 | 389 | $key = null; |
| 375 | 390 | foreach ($this as $k => $v) { |
| 376 | - if ($predicate($v, $k)) |
|
| 377 | - $key = $k; |
|
| 391 | + if ($predicate($v, $k)) { |
|
| 392 | + $key = $k; |
|
| 393 | + } |
|
| 378 | 394 | } |
| 379 | 395 | return $key; // not -1 |
| 380 | 396 | } |
@@ -393,8 +409,9 @@ discard block |
||
| 393 | 409 | return new self(function () use ($count) { |
| 394 | 410 | $it = $this->getIterator(); |
| 395 | 411 | $it->rewind(); |
| 396 | - for ($i = 0; $i < $count && $it->valid(); ++$i) |
|
| 397 | - $it->next(); |
|
| 412 | + for ($i = 0; $i < $count && $it->valid(); ++$i) { |
|
| 413 | + $it->next(); |
|
| 414 | + } |
|
| 398 | 415 | while ($it->valid()) { |
| 399 | 416 | yield $it->key() => $it->current(); |
| 400 | 417 | $it->next(); |
@@ -418,10 +435,12 @@ discard block |
||
| 418 | 435 | return new self(function () use ($predicate) { |
| 419 | 436 | $yielding = false; |
| 420 | 437 | foreach ($this as $k => $v) { |
| 421 | - if (!$yielding && !$predicate($v, $k)) |
|
| 422 | - $yielding = true; |
|
| 423 | - if ($yielding) |
|
| 424 | - yield $k => $v; |
|
| 438 | + if (!$yielding && !$predicate($v, $k)) { |
|
| 439 | + $yielding = true; |
|
| 440 | + } |
|
| 441 | + if ($yielding) { |
|
| 442 | + yield $k => $v; |
|
| 443 | + } |
|
| 425 | 444 | } |
| 426 | 445 | }); |
| 427 | 446 | } |
@@ -437,14 +456,16 @@ discard block |
||
| 437 | 456 | */ |
| 438 | 457 | public function take ($count) |
| 439 | 458 | { |
| 440 | - if ($count <= 0) |
|
| 441 | - return new self(new \EmptyIterator, false); |
|
| 459 | + if ($count <= 0) { |
|
| 460 | + return new self(new \EmptyIterator, false); |
|
| 461 | + } |
|
| 442 | 462 | |
| 443 | 463 | return new self(function () use ($count) { |
| 444 | 464 | foreach ($this as $k => $v) { |
| 445 | 465 | yield $k => $v; |
| 446 | - if (--$count == 0) |
|
| 447 | - break; |
|
| 466 | + if (--$count == 0) { |
|
| 467 | + break; |
|
| 468 | + } |
|
| 448 | 469 | } |
| 449 | 470 | }); |
| 450 | 471 | } |
@@ -464,8 +485,9 @@ discard block |
||
| 464 | 485 | |
| 465 | 486 | return new self(function () use ($predicate) { |
| 466 | 487 | foreach ($this as $k => $v) { |
| 467 | - if (!$predicate($v, $k)) |
|
| 468 | - break; |
|
| 488 | + if (!$predicate($v, $k)) { |
|
| 489 | + break; |
|
| 490 | + } |
|
| 469 | 491 | yield $k => $v; |
| 470 | 492 | } |
| 471 | 493 | }); |
@@ -38,11 +38,11 @@ discard block |
||
| 38 | 38 | * @codeCoverageIgnore |
| 39 | 39 | * @internal |
| 40 | 40 | */ |
| 41 | - public static function init () |
|
| 41 | + public static function init() |
|
| 42 | 42 | { |
| 43 | 43 | self::$lambdaCache = [ |
| 44 | - '$v' => [ 'v,k' => Functions::$value ], |
|
| 45 | - '$k' => [ 'v,k' => Functions::$key ], |
|
| 44 | + '$v' => ['v,k' => Functions::$value], |
|
| 45 | + '$k' => ['v,k' => Functions::$key], |
|
| 46 | 46 | ]; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @throws \InvalidArgumentException Incorrect lambda syntax. |
| 56 | 56 | * @return callable|null |
| 57 | 57 | */ |
| 58 | - public static function createLambda ($closure, $closureArgs, $default = null) |
|
| 58 | + public static function createLambda($closure, $closureArgs, $default = null) |
|
| 59 | 59 | { |
| 60 | 60 | if ($closure === null) { |
| 61 | 61 | if ($default === null) |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @throws \InvalidArgumentException Incorrect lambda syntax. |
| 81 | 81 | * @throws \InvalidArgumentException Incorrect SORT_ flags. |
| 82 | 82 | */ |
| 83 | - public static function createComparer ($closure, $sortOrder, &$isReversed) |
|
| 83 | + public static function createComparer($closure, $sortOrder, &$isReversed) |
|
| 84 | 84 | { |
| 85 | 85 | if ($closure === null) { |
| 86 | 86 | $isReversed = false; |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * @param int|bool $sortOrder |
| 117 | 117 | * @return callable|string|int|null |
| 118 | 118 | */ |
| 119 | - public static function lambdaToSortFlagsAndOrder ($closure, &$sortOrder) |
|
| 119 | + public static function lambdaToSortFlagsAndOrder($closure, &$sortOrder) |
|
| 120 | 120 | { |
| 121 | 121 | if ($sortOrder !== SORT_ASC && $sortOrder !== SORT_DESC) |
| 122 | 122 | $sortOrder = $sortOrder ? SORT_DESC : SORT_ASC; |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @throws \InvalidArgumentException Incorrect lambda syntax. |
| 136 | 136 | * @return string|null |
| 137 | 137 | */ |
| 138 | - private static function createLambdaFromString ($closure, $closureArgs) |
|
| 138 | + private static function createLambdaFromString($closure, $closureArgs) |
|
| 139 | 139 | { |
| 140 | 140 | $posDollar = strpos($closure, '$'); |
| 141 | 141 | if ($posDollar !== false) { |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $code = substr($closure, $posArrow + 3); |
| 148 | 148 | } |
| 149 | 149 | else { |
| 150 | - $args = '$' . str_replace(',', '=null,$', $closureArgs) . '=null'; |
|
| 150 | + $args = '$'.str_replace(',', '=null,$', $closureArgs).'=null'; |
|
| 151 | 151 | $code = $closure; |
| 152 | 152 | } |
| 153 | 153 | $code = trim($code, " \r\n\t"); |
@@ -58,16 +58,20 @@ discard block |
||
| 58 | 58 | public static function createLambda ($closure, $closureArgs, $default = null) |
| 59 | 59 | { |
| 60 | 60 | if ($closure === null) { |
| 61 | - if ($default === null) |
|
| 62 | - throw new \InvalidArgumentException(self::ERROR_CLOSURE_NULL); |
|
| 61 | + if ($default === null) { |
|
| 62 | + throw new \InvalidArgumentException(self::ERROR_CLOSURE_NULL); |
|
| 63 | + } |
|
| 63 | 64 | return $default; |
| 64 | 65 | } |
| 65 | - if ($closure instanceof \Closure) |
|
| 66 | - return $closure; |
|
| 67 | - if (is_string($closure) && ($function = self::createLambdaFromString($closure, $closureArgs))) |
|
| 68 | - return $function; |
|
| 69 | - if (is_callable($closure)) |
|
| 70 | - return $closure; |
|
| 66 | + if ($closure instanceof \Closure) { |
|
| 67 | + return $closure; |
|
| 68 | + } |
|
| 69 | + if (is_string($closure) && ($function = self::createLambdaFromString($closure, $closureArgs))) { |
|
| 70 | + return $function; |
|
| 71 | + } |
|
| 72 | + if (is_callable($closure)) { |
|
| 73 | + return $closure; |
|
| 74 | + } |
|
| 71 | 75 | throw new \InvalidArgumentException(self::ERROR_CLOSURE_NOT_CALLABLE); |
| 72 | 76 | } |
| 73 | 77 | |
@@ -85,8 +89,7 @@ discard block |
||
| 85 | 89 | if ($closure === null) { |
| 86 | 90 | $isReversed = false; |
| 87 | 91 | return $sortOrder === SORT_DESC ? Functions::$compareStrictReversed : Functions::$compareStrict; |
| 88 | - } |
|
| 89 | - elseif (is_int($closure)) { |
|
| 92 | + } elseif (is_int($closure)) { |
|
| 90 | 93 | switch ($closure) { |
| 91 | 94 | case SORT_REGULAR: |
| 92 | 95 | return Functions::$compareStrict; |
@@ -118,14 +121,16 @@ discard block |
||
| 118 | 121 | */ |
| 119 | 122 | public static function lambdaToSortFlagsAndOrder ($closure, &$sortOrder) |
| 120 | 123 | { |
| 121 | - if ($sortOrder !== SORT_ASC && $sortOrder !== SORT_DESC) |
|
| 122 | - $sortOrder = $sortOrder ? SORT_DESC : SORT_ASC; |
|
| 123 | - if (is_int($closure)) |
|
| 124 | - return $closure; |
|
| 125 | - elseif (($closure === null || is_string($closure)) && isset(self::$compareFunctionToSortFlags[$closure])) |
|
| 126 | - return self::$compareFunctionToSortFlags[$closure]; |
|
| 127 | - else |
|
| 128 | - return null; |
|
| 124 | + if ($sortOrder !== SORT_ASC && $sortOrder !== SORT_DESC) { |
|
| 125 | + $sortOrder = $sortOrder ? SORT_DESC : SORT_ASC; |
|
| 126 | + } |
|
| 127 | + if (is_int($closure)) { |
|
| 128 | + return $closure; |
|
| 129 | + } elseif (($closure === null || is_string($closure)) && isset(self::$compareFunctionToSortFlags[$closure])) { |
|
| 130 | + return self::$compareFunctionToSortFlags[$closure]; |
|
| 131 | + } else { |
|
| 132 | + return null; |
|
| 133 | + } |
|
| 129 | 134 | } |
| 130 | 135 | |
| 131 | 136 | /** |
@@ -139,24 +144,26 @@ discard block |
||
| 139 | 144 | { |
| 140 | 145 | $posDollar = strpos($closure, '$'); |
| 141 | 146 | if ($posDollar !== false) { |
| 142 | - if (isset(self::$lambdaCache[$closure][$closureArgs])) |
|
| 143 | - return self::$lambdaCache[$closure][$closureArgs]; |
|
| 147 | + if (isset(self::$lambdaCache[$closure][$closureArgs])) { |
|
| 148 | + return self::$lambdaCache[$closure][$closureArgs]; |
|
| 149 | + } |
|
| 144 | 150 | $posArrow = strpos($closure, '==>', $posDollar); |
| 145 | 151 | if ($posArrow !== false) { |
| 146 | 152 | $args = trim(substr($closure, 0, $posArrow), "() \r\n\t"); |
| 147 | 153 | $code = substr($closure, $posArrow + 3); |
| 148 | - } |
|
| 149 | - else { |
|
| 154 | + } else { |
|
| 150 | 155 | $args = '$' . str_replace(',', '=null,$', $closureArgs) . '=null'; |
| 151 | 156 | $code = $closure; |
| 152 | 157 | } |
| 153 | 158 | $code = trim($code, " \r\n\t"); |
| 154 | - if (strlen($code) > 0 && $code[0] != '{') |
|
| 155 | - $code = "return {$code};"; |
|
| 159 | + if (strlen($code) > 0 && $code[0] != '{') { |
|
| 160 | + $code = "return {$code};"; |
|
| 161 | + } |
|
| 156 | 162 | $fun = @create_function($args, $code); |
| 157 | 163 | // @codeCoverageIgnoreStart |
| 158 | - if (!$fun) |
|
| 159 | - throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA); |
|
| 164 | + if (!$fun) { |
|
| 165 | + throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA); |
|
| 166 | + } |
|
| 160 | 167 | // @codeCoverageIgnoreEnd |
| 161 | 168 | self::$lambdaCache[$closure][$closureArgs] = $fun; |
| 162 | 169 | return $fun; |