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:43
created

Sorted::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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
		}
31
        for ($i = 1; $i < $count; $i++) {
32
            if (
33
                ($this->ascending && ($this->fn)($input[$i]) < ($this->fn)($input[$i - 1]))
34
                || (!$this->ascending && ($this->fn)($input[$i]) > ($this->fn)($input[$i - 1]))
35
            ) {
36
                return false;
37
            };
38
        }
39
        return true;
40
    }
41
}
42