CountFactors   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 17
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A solution() 0 14 3
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