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 (#836)
by
unknown
09:02
created

Sorted::validate()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 10
nc 4
nop 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
namespace Respect\Validation\Rules;
13
14
class Sorted extends AbstractRule
15
{
16
    public $fn = null;
17
    public $ascending = true;
18
19
    public function __construct(callable $fn = null, bool $ascending = true)
20
    {
21
        $this->fn = $fn ?? function($x){ return $x;};
22
        $this->ascending = $ascending;
23
    }
24
25
    public function validate($input)
26
    {
27
        $count = count($input);
28
        if ($count < 2)
29
            return true;
30
        for ($i = 1; $i < $count; $i++) {
31
            if (
32
                ($this->ascending && ($this->fn)($input[$i]) < ($this->fn)($input[$i - 1]))
33
                || (!$this->ascending && ($this->fn)($input[$i]) > ($this->fn)($input[$i - 1]))
34
            )
35
                return false;
36
        }
37
        return true;
38
    }
39
}
40