Completed
Push — master ( b221ab...d54b1b )
by Alexander
14s
created
YaLinqo/EnumerablePagination.php 1 patch
Braces   +67 added lines, -46 removed lines patch added patch discarded remove patch
@@ -32,14 +32,16 @@  discard block
 block discarded – undo
32 32
         $it = $this->getIterator();
33 33
 
34 34
         if ($it instanceof \ArrayAccess) {
35
-            if (!$it->offsetExists($key))
36
-                throw new \UnexpectedValueException(Errors::NO_KEY);
35
+            if (!$it->offsetExists($key)) {
36
+                            throw new \UnexpectedValueException(Errors::NO_KEY);
37
+            }
37 38
             return $it->offsetGet($key);
38 39
         }
39 40
 
40 41
         foreach ($it as $k => $v) {
41
-            if ($k === $key)
42
-                return $v;
42
+            if ($k === $key) {
43
+                            return $v;
44
+            }
43 45
         }
44 46
         throw new \UnexpectedValueException(Errors::NO_KEY);
45 47
     }
@@ -58,12 +60,14 @@  discard block
 block discarded – undo
58 60
         /** @var $it \Iterator|\ArrayAccess */
59 61
         $it = $this->getIterator();
60 62
 
61
-        if ($it instanceof \ArrayAccess)
62
-            return $it->offsetExists($key) ? $it->offsetGet($key) : $default;
63
+        if ($it instanceof \ArrayAccess) {
64
+                    return $it->offsetExists($key) ? $it->offsetGet($key) : $default;
65
+        }
63 66
 
64 67
         foreach ($it as $k => $v) {
65
-            if ($k === $key)
66
-                return $v;
68
+            if ($k === $key) {
69
+                            return $v;
70
+            }
67 71
         }
68 72
         return $default;
69 73
     }
@@ -86,8 +90,9 @@  discard block
 block discarded – undo
86 90
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
87 91
 
88 92
         foreach ($this as $k => $v) {
89
-            if ($predicate($v, $k))
90
-                return $v;
93
+            if ($predicate($v, $k)) {
94
+                            return $v;
95
+            }
91 96
         }
92 97
         throw new \UnexpectedValueException(Errors::NO_MATCHES);
93 98
     }
@@ -109,8 +114,9 @@  discard block
 block discarded – undo
109 114
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
110 115
 
111 116
         foreach ($this as $k => $v) {
112
-            if ($predicate($v, $k))
113
-                return $v;
117
+            if ($predicate($v, $k)) {
118
+                            return $v;
119
+            }
114 120
         }
115 121
         return $default;
116 122
     }
@@ -132,8 +138,9 @@  discard block
 block discarded – undo
132 138
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
133 139
 
134 140
         foreach ($this as $k => $v) {
135
-            if ($predicate($v, $k))
136
-                return $v;
141
+            if ($predicate($v, $k)) {
142
+                            return $v;
143
+            }
137 144
         }
138 145
         return $fallback();
139 146
     }
@@ -163,8 +170,9 @@  discard block
 block discarded – undo
163 170
                 $value = $v;
164 171
             }
165 172
         }
166
-        if (!$found)
167
-            throw new \UnexpectedValueException(Errors::NO_MATCHES);
173
+        if (!$found) {
174
+                    throw new \UnexpectedValueException(Errors::NO_MATCHES);
175
+        }
168 176
         return $value;
169 177
     }
170 178
 
@@ -243,14 +251,16 @@  discard block
 block discarded – undo
243 251
         $value = null;
244 252
         foreach ($this as $k => $v) {
245 253
             if ($predicate($v, $k)) {
246
-                if ($found)
247
-                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
254
+                if ($found) {
255
+                                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
256
+                }
248 257
                 $found = true;
249 258
                 $value = $v;
250 259
             }
251 260
         }
252
-        if (!$found)
253
-            throw new \UnexpectedValueException(Errors::NO_MATCHES);
261
+        if (!$found) {
262
+                    throw new \UnexpectedValueException(Errors::NO_MATCHES);
263
+        }
254 264
         return $value;
255 265
     }
256 266
 
@@ -275,8 +285,9 @@  discard block
 block discarded – undo
275 285
         $value = null;
276 286
         foreach ($this as $k => $v) {
277 287
             if ($predicate($v, $k)) {
278
-                if ($found)
279
-                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
288
+                if ($found) {
289
+                                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
290
+                }
280 291
                 $found = true;
281 292
                 $value = $v;
282 293
             }
@@ -305,8 +316,9 @@  discard block
 block discarded – undo
305 316
         $value = null;
306 317
         foreach ($this as $k => $v) {
307 318
             if ($predicate($v, $k)) {
308
-                if ($found)
309
-                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
319
+                if ($found) {
320
+                                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
321
+                }
310 322
                 $found = true;
311 323
                 $value = $v;
312 324
             }
@@ -328,11 +340,11 @@  discard block
 block discarded – undo
328 340
         if ($array !== null) {
329 341
             $keys = array_keys($array, $value, true);
330 342
             return empty($keys) ? null : $keys[0];
331
-        }
332
-        else {
343
+        } else {
333 344
             foreach ($this as $k => $v) {
334
-                if ($v === $value)
335
-                    return $k;
345
+                if ($v === $value) {
346
+                                    return $k;
347
+                }
336 348
             }
337 349
             return null;
338 350
         }
@@ -350,8 +362,9 @@  discard block
 block discarded – undo
350 362
     {
351 363
         $key = null;
352 364
         foreach ($this as $k => $v) {
353
-            if ($v === $value)
354
-                $key = $k;
365
+            if ($v === $value) {
366
+                            $key = $k;
367
+            }
355 368
         }
356 369
         return $key; // not -1
357 370
     }
@@ -369,8 +382,9 @@  discard block
 block discarded – undo
369 382
         $predicate = Utils::createLambda($predicate, 'v,k');
370 383
 
371 384
         foreach ($this as $k => $v) {
372
-            if ($predicate($v, $k))
373
-                return $k;
385
+            if ($predicate($v, $k)) {
386
+                            return $k;
387
+            }
374 388
         }
375 389
         return null; // not -1
376 390
     }
@@ -389,8 +403,9 @@  discard block
 block discarded – undo
389 403
 
390 404
         $key = null;
391 405
         foreach ($this as $k => $v) {
392
-            if ($predicate($v, $k))
393
-                $key = $k;
406
+            if ($predicate($v, $k)) {
407
+                            $key = $k;
408
+            }
394 409
         }
395 410
         return $key; // not -1
396 411
     }
@@ -409,8 +424,9 @@  discard block
 block discarded – undo
409 424
         return new self(function() use ($count) {
410 425
             $it = $this->getIterator();
411 426
             $it->rewind();
412
-            for ($i = 0; $i < $count && $it->valid(); ++$i)
413
-                $it->next();
427
+            for ($i = 0; $i < $count && $it->valid(); ++$i) {
428
+                            $it->next();
429
+            }
414 430
             while ($it->valid()) {
415 431
                 yield $it->key() => $it->current();
416 432
                 $it->next();
@@ -434,10 +450,12 @@  discard block
 block discarded – undo
434 450
         return new self(function() use ($predicate) {
435 451
             $yielding = false;
436 452
             foreach ($this as $k => $v) {
437
-                if (!$yielding && !$predicate($v, $k))
438
-                    $yielding = true;
439
-                if ($yielding)
440
-                    yield $k => $v;
453
+                if (!$yielding && !$predicate($v, $k)) {
454
+                                    $yielding = true;
455
+                }
456
+                if ($yielding) {
457
+                                    yield $k => $v;
458
+                }
441 459
             }
442 460
         });
443 461
     }
@@ -453,14 +471,16 @@  discard block
 block discarded – undo
453 471
      */
454 472
     public function take(int $count)
455 473
     {
456
-        if ($count <= 0)
457
-            return new self(new \EmptyIterator, false);
474
+        if ($count <= 0) {
475
+                    return new self(new \EmptyIterator, false);
476
+        }
458 477
 
459 478
         return new self(function() use ($count) {
460 479
             foreach ($this as $k => $v) {
461 480
                 yield $k => $v;
462
-                if (--$count == 0)
463
-                    break;
481
+                if (--$count == 0) {
482
+                                    break;
483
+                }
464 484
             }
465 485
         });
466 486
     }
@@ -480,8 +500,9 @@  discard block
 block discarded – undo
480 500
 
481 501
         return new self(function() use ($predicate) {
482 502
             foreach ($this as $k => $v) {
483
-                if (!$predicate($v, $k))
484
-                    break;
503
+                if (!$predicate($v, $k)) {
504
+                                    break;
505
+                }
485 506
                 yield $k => $v;
486 507
             }
487 508
         });
Please login to merge, or discard this patch.