| Total Complexity | 8 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class Factorial |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Temporary value for the recursive value. |
||
| 9 | */ |
||
| 10 | protected int $result = 1; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Create a new instance class. |
||
| 14 | * |
||
| 15 | * @return void |
||
| 16 | */ |
||
| 17 | 3 | public function __construct(protected int $initialN) |
|
| 18 | { |
||
| 19 | // |
||
| 20 | 3 | } |
|
| 21 | |||
| 22 | /** |
||
| 23 | * Return result of the factorial using loop way. |
||
| 24 | */ |
||
| 25 | 1 | public function resultWithLoop(): int |
|
| 26 | { |
||
| 27 | 1 | if ($this->initialN <= 1) { |
|
| 28 | 1 | return 1; |
|
| 29 | } |
||
| 30 | |||
| 31 | 1 | $result = 1; |
|
| 32 | |||
| 33 | 1 | for ($n = $this->initialN; $n >= 1; $n--) { |
|
| 34 | 1 | $result *= $n; |
|
| 35 | } |
||
| 36 | |||
| 37 | 1 | return $result; |
|
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Return result of the factorial using recursive way. |
||
| 42 | */ |
||
| 43 | 1 | public function resultWithRecursive(): int |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Return result of the factorial using tail recursive way. |
||
| 56 | */ |
||
| 57 | 1 | public function resultWithTailRecursive(): int |
|
| 69 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.