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

PrimeNumber   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 8
dl 0
loc 22
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B isValid() 0 17 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
use function ceil;
17
use function is_numeric;
18
use function sqrt;
19
20
/**
21
 * Validates whether the input is a prime number.
22
 *
23
 * @author Alexandre Gomes Gaigalas <[email protected]>
24
 * @author Camilo Teixeira de Melo <[email protected]>
25
 * @author Henrique Moody <[email protected]>
26
 * @author Ismael Elias <[email protected]>
27
 * @author Kleber Hamada Sato <[email protected]>
28
 */
29
final class PrimeNumber extends AbstractRule
30
{
31
    /**
32
     * {@inheritdoc}
33
     */
34 20
    public function isValid($input): bool
35
    {
36 20
        if (!is_numeric($input) || $input <= 1) {
37 10
            return false;
38
        }
39
40 11
        if (2 != $input && 0 == ($input % 2)) {
41 3
            return false;
42
        }
43
44 9
        for ($i = 3; $i <= ceil(sqrt((float) $input)); $i += 2) {
45 7
            if (0 == ($input % $i)) {
46 2
                return false;
47
            }
48
        }
49
50 7
        return true;
51
    }
52
}
53