IsPrime::__invoke()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 26
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 9.5555
cc 5
nc 5
nop 1
crap 5
1
<?php
2
/**
3
 * Created by gerk on 01.12.17 23:33
4
 */
5
6
namespace PeekAndPoke\Component\Psi\Psi\Num;
7
8
use PeekAndPoke\Component\Psi\UnaryFunction;
9
10
/**
11
 *
12
 *
13
 * @author Karsten J. Gerber <[email protected]>
14
 */
15
class IsPrime implements UnaryFunction
16
{
17
    /**
18
     * @param mixed $input
19
     *
20
     * @return bool
21
     */
22 3
    public function __invoke($input)
23
    {
24 3
        if (! is_int($input)) {
25 1
            return false;
26
        }
27
28 2
        $n = abs($input);
29
30 2
        if ($n < 2) {
31 2
            return false;
32
        }
33
34 2
        $sqrt = sqrt($n);
35
36 2
        $i = 2;
37
38 2
        while ($i <= $sqrt) {
39
40 2
            if ($n % $i === 0) {
41 2
                return false;
42
            }
43
44 2
            $i++;
45
        }
46
47 2
        return true;
48
    }
49
}
50