Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#1207)
by
unknown
03:37
created

Sorted::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use function count;
17
18
/**
19
 * @author Henrique Moody <[email protected]>
20
 * @author Mikhail Vyrtsev <[email protected]>
21
 */
22
final class Sorted extends AbstractRule
23
{
24
    /**
25
     * @var callable
26
     */
27
    private $fn = null;
28
29
    /**
30
     * @var bool
31
     */
32
    private $ascending = true;
33
34 7
    public function __construct(?callable $fn = null, bool $ascending = true)
35
    {
36
        $this->fn = $fn ?? static function ($x) {
37 7
            return $x;
38 1
        };
39 1
        $this->ascending = $ascending;
40 1
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 10
    public function validate($input): bool
46
    {
47 10
        $count = count($input);
48 10
        if ($count < 2) {
49 1
            return true;
50
        }
51 9
        for ($i = 1; $i < $count; ++$i) {
52 9
            if (($this->ascending && ($this->fn)($input[$i]) < ($this->fn)($input[$i - 1]))
53 9
                || (!$this->ascending && ($this->fn)($input[$i]) > ($this->fn)($input[$i - 1]))
54
            ) {
55 4
                return false;
56
            }
57
        }
58
59 6
        return true;
60
    }
61
}
62