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
05:58
created

Sorted   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B validate() 0 16 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
        $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