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
Push — 1.1 ( fca464...0e73bc )
by Henrique
09:36 queued 06:14
created

Factor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 35
c 0
b 0
f 0
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A validate() 0 20 5
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
use Respect\Validation\Exceptions\ComponentException;
15
use Respect\Validation\Exceptions\ValidationException;
16
17
/**
18
 * @author David Meister <[email protected]>
19
 */
20
class Factor extends AbstractRule
21
{
22
    public $dividend;
23
24 321
    public function __construct($dividend)
25
    {
26 321
        if (!is_numeric($dividend) || (int) $dividend != $dividend) {
27 17
            $message = 'Dividend %s must be an integer';
28 17
            throw new ComponentException(sprintf($message, ValidationException::stringify($dividend)));
29
        }
30
31 304
        $this->dividend = (int) $dividend;
32 304
    }
33
34 304
    public function validate($input)
35
    {
36
        // Every integer is a factor of zero, and zero is the only integer that
37
        // has zero for a factor.
38 304
        if ($this->dividend === 0) {
39 36
            return true;
40
        }
41
42
        // Factors must be integers that are not zero.
43 268
        if (!is_numeric($input) || (int) $input != $input || $input == 0) {
44 40
            return false;
45
        }
46
47 228
        $input = (int) abs($input);
48 228
        $dividend = (int) abs($this->dividend);
49
50
        // The dividend divided by the input must be an integer if input is a
51
        // factor of the dividend.
52 228
        return is_integer($dividend / $input);
53
    }
54
}
55