Passed
Push — master ( 9fe25d...e6dd30 )
by Christian
02:33
created

Helper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 24
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getStringComparator() 0 4 1
A getObjectSafeComparator() 0 4 2
A unwrapDeferred() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RemotelyLiving\PHPCollection;
6
7
final class Helper
8
{
9
    public static function getStringComparator(): callable
10
    {
11
        return function ($a, $b): int {
12
            return strcmp((string) $a, (string) $b);
13
        };
14
    }
15
16
    public static function getObjectSafeComparator(): callable
17
    {
18
        return function ($a, $b): int {
19
            return (\gettype($a) === \gettype($b)) ? $a <=> $b : -1;
20
        };
21
    }
22
23
    public static function unwrapDeferred(\Generator $deferredValues): array
24
    {
25
        $items = [];
26
        foreach ($deferredValues as $key => $item) {
27
            $items[$key] = $item;
28
        }
29
30
        return $items;
31
    }
32
}
33