Issues (4)

src/Link/SortKeys.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Cocur\Chain\Link;
4
5
/**
6
 * Class SortKeys.
7
 *
8
 * @author      Christoph Rosse
9
 * @author      Florian Eckerstorfer <[email protected]>
10
 */
11
trait SortKeys
12
{
13
    /**
14
     * Sort a Chain by its keys.
15
     *
16
     * @param int|callable $sortBy
17
     * @param array        $options
18
     *
19
     * @return self
20
     */
21 4
    public function sortKeys($sortBy = SORT_REGULAR, array $options = []): self
22
    {
23 4
        if ($sortBy && is_callable($sortBy)) {
24 1
            uksort($this->array, $sortBy);
0 ignored issues
show
It seems like $sortBy can also be of type integer; however, parameter $cmp_function of uksort() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

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

24
            uksort($this->array, /** @scrutinizer ignore-type */ $sortBy);
Loading history...
25
        } else {
26 3
            $this->sortKeysWithFlags($sortBy, $options);
0 ignored issues
show
It seems like $sortBy can also be of type callable; however, parameter $sortFlags of Cocur\Chain\Link\SortKeys::sortKeysWithFlags() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

26
            $this->sortKeysWithFlags(/** @scrutinizer ignore-type */ $sortBy, $options);
Loading history...
27
        }
28
29 4
        return $this;
30
    }
31
32
    /**
33
     * @param int   $sortFlags
34
     * @param array $options
35
     */
36 3
    private function sortKeysWithFlags(int $sortFlags = SORT_REGULAR, array $options = []): void
37
    {
38 3
        if (!empty($options['reverse'])) {
39 1
            krsort($this->array, $sortFlags);
40
        } else {
41 2
            ksort($this->array, $sortFlags);
42
        }
43 3
    }
44
}
45