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

Sorted::validate()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5.025

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 10
cp 0.9
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 6
nop 1
crap 5.025
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 function __construct(callable $fn = null, bool $ascending = true)
17
    {
18
        $this->fn = $fn ?? function($x){ return $x;};
0 ignored issues
show
Bug introduced by
The property fn does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19 5
        $this->ascending = $ascending;
0 ignored issues
show
Bug introduced by
The property ascending does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
20 5
    }
21
22 5
    public function validate($input)
23
    {
24 5
        $count = count($input);
25 5
        if($count < 2){
26
            return true;
27
        };
28 5
        for($i = 1; $i < $count; $i++){
29 5
            $cmp = $this->ascending === true
30 4
                ? ($this->fn)($input[$i]) > ($this->fn)($input[$i - 1])
31 5
                : ($this->fn)($input[$i]) < ($this->fn)($input[$i - 1]);
32 5
            if($cmp === false) return false;
33
        }
34 3
        return true;
35
    }
36
}
37