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
Pull Request — master (#1087)
by Henrique
02:56
created

Factor::isValid()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 3
nop 1
dl 0
loc 19
ccs 8
cts 8
cp 1
crap 5
rs 9.6111
c 0
b 0
f 0
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
use Respect\Validation\Exceptions\ComponentException;
17
use function Respect\Stringifier\stringify;
18
19
/**
20
 * @author David Meister <[email protected]>
21
 */
22
class Factor extends AbstractRule
23
{
24
    public $dividend;
25
26 321
    public function __construct($dividend)
27
    {
28 321
        if (!is_numeric($dividend) || (int) $dividend != $dividend) {
29 17
            $message = 'Dividend %s must be an integer';
30 17
            throw new ComponentException(sprintf($message, stringify($dividend)));
31
        }
32
33 304
        $this->dividend = (int) $dividend;
34 304
    }
35
36 304
    public function isValid($input): bool
37
    {
38
        // Every integer is a factor of zero, and zero is the only integer that
39
        // has zero for a factor.
40 304
        if (0 === $this->dividend) {
41 36
            return true;
42
        }
43
44
        // Factors must be integers that are not zero.
45 268
        if (!is_numeric($input) || (int) $input != $input || 0 == $input) {
46 40
            return false;
47
        }
48
49 228
        $input = (int) abs($input);
50 228
        $dividend = (int) abs($this->dividend);
51
52
        // The dividend divided by the input must be an integer if input is a
53
        // factor of the dividend.
54 228
        return is_integer($dividend / $input);
55
    }
56
}
57