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
03:19
created

Sorted::validate()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 9
nc 4
nop 1
crap 7
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 7
        $this->ascending = $ascending;
23 7
    }
24
25 7
    public function validate($input)
26
    {
27 7
        $count = count($input);
28 7
        if($count < 2) return true;
29 7
        for($i = 1; $i < $count; $i++){
30
            if(
31 7
                ($this->ascending && ($this->fn)($input[$i]) < ($this->fn)($input[$i - 1]))
32 7
                || (!$this->ascending && ($this->fn)($input[$i]) > ($this->fn)($input[$i - 1]))
33
            ){
34 2
                return false;
35
            };
36
        }
37 5
        return true;
38
    }
39
}
40