CountFactors::solution()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace Lesson08;
4
5
class CountFactors
6
{
7
    public function solution($N)
8
    {
9
        $root = (int) ceil(sqrt($N));
10
        $numberOfFactors = [];
11
        for ($i = 1; $i <= $root; $i++) {
12
            if ($N % $i === 0) {
13
                $j = $N / $i;
14
                $numberOfFactors[] = $i;
15
                $numberOfFactors[] = $j;
16
            }
17
        }
18
19
        return count(array_unique($numberOfFactors));
20
    }
21
}
22