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

Passed
Pull Request — master (#1087)
by Henrique
03:56 queued 01:10
created

Sorted::isValid()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 7.0671

Importance

Changes 0
Metric Value
cc 7
eloc 9
nc 4
nop 1
dl 0
loc 16
ccs 8
cts 9
cp 0.8889
crap 7.0671
rs 8.8333
c 0
b 0
f 0
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
class Sorted extends AbstractRule
17
{
18
    public $fn = null;
19
    public $ascending = true;
20
21 7
    public function __construct(callable $fn = null, bool $ascending = true)
22
    {
23
        $this->fn = $fn ?? function ($x) { return $x; };
24 7
        $this->ascending = $ascending;
25 7
    }
26
27 7
    public function isValid($input): bool
28
    {
29 7
        $count = count($input);
30 7
        if ($count < 2) {
31
            return true;
32
        }
33 7
        for ($i = 1; $i < $count; ++$i) {
34
            if (
35 7
                ($this->ascending && ($this->fn)($input[$i]) < ($this->fn)($input[$i - 1]))
36 7
                || (!$this->ascending && ($this->fn)($input[$i]) > ($this->fn)($input[$i - 1]))
37
            ) {
38 2
                return false;
39
            }
40
        }
41
42 5
        return true;
43
    }
44
}
45