Helper::getStringComparator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
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