Sorted::by()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 16
rs 9.2222
cc 6
nc 5
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Sorting;
4
5
use Stratadox\Sorting\Contracts\Sorting;
6
7
final class Sorted
8
{
9
    public static function by(array $fields): Sorting
10
    {
11
        /** @var Sort|null $sorting */
12
        $sorting = null;
13
        foreach ($fields as $field => $ascend) {
14
            if ($sorting === null) {
15
                $sorting = $ascend ?
16
                    Sort::ascendingBy($field) :
17
                    Sort::descendingBy($field);
18
            } else {
19
                $sorting = $ascend ?
20
                    $sorting->andThenAscendingBy($field) :
0 ignored issues
show
Bug introduced by
The method andThenAscendingBy() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
                    $sorting->/** @scrutinizer ignore-call */ 
21
                              andThenAscendingBy($field) :

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
                    $sorting->andThenDescendingBy($field);
22
            }
23
        }
24
        return $sorting ?: NoSorting::needed();
25
    }
26
}
27