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
Push — master ( 9c7550...b7043b )
by Henrique
04:02
created

Sorted   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 8
eloc 14
dl 0
loc 28
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B validate() 0 15 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
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
/**
17
 * @author Henrique Moody <[email protected]>
18
 * @author Mikhail Vyrtsev <[email protected]>
19
 */
20
class Sorted extends AbstractRule
21
{
22
    public $fn = null;
23
    public $ascending = true;
24
25 7
    public function __construct(callable $fn = null, bool $ascending = true)
26
    {
27
        $this->fn = $fn ?? function ($x) {
28 5
            return $x;
29 5
        };
30 7
        $this->ascending = $ascending;
31 7
    }
32
33 7
    public function validate($input): bool
34
    {
35 7
        $count = count($input);
36 7
        if ($count < 2) {
37
            return true;
38
        }
39 7
        for ($i = 1; $i < $count; ++$i) {
40 7
            if (($this->ascending && ($this->fn)($input[$i]) < ($this->fn)($input[$i - 1]))
41 7
                || (!$this->ascending && ($this->fn)($input[$i]) > ($this->fn)($input[$i - 1]))
42
            ) {
43 2
                return false;
44
            }
45
        }
46
47 5
        return true;
48
    }
49
}
50