| Total Complexity | 8 |
| Total Lines | 71 |
| 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 | * @var int |
||
| 11 | */ |
||
| 12 | protected int $result = 1; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Create a new instance class. |
||
| 16 | * |
||
| 17 | * @param int $initialN |
||
| 18 | * @return void |
||
| 19 | */ |
||
| 20 | 3 | public function __construct(protected int $initialN) |
|
| 21 | { |
||
| 22 | // |
||
| 23 | 3 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * Return result of the factorial using loop way. |
||
| 27 | * |
||
| 28 | * @return int |
||
| 29 | */ |
||
| 30 | 1 | public function resultWithLoop(): int |
|
| 31 | { |
||
| 32 | 1 | if ($this->initialN <= 1) { |
|
| 33 | 1 | return 1; |
|
| 34 | } |
||
| 35 | |||
| 36 | 1 | $result = 1; |
|
| 37 | |||
| 38 | 1 | for ($n = $this->initialN; $n >= 1; $n--) { |
|
| 39 | 1 | $result *= $n; |
|
| 40 | } |
||
| 41 | |||
| 42 | 1 | return $result; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Return result of the factorial using recursive way. |
||
| 47 | * |
||
| 48 | * @return int |
||
| 49 | */ |
||
| 50 | 1 | public function resultWithRecursive(): int |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Return result of the factorial using tail recursive way. |
||
| 63 | * |
||
| 64 | * @return int |
||
| 65 | */ |
||
| 66 | 1 | public function resultWithTailRecursive(): int |
|
| 78 |
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.