Refactoring¶
Refactoring, in PHP as in any programming language, refers to the process of restructuring and improving the codebase of a PHP application without changing its external behavior. The primary goal of refactoring is to make the code more readable, maintainable, and efficient while reducing code duplication and potential bugs. Refactoring is an essential practice in software development to ensure that the code remains clean and adaptable as the project evolves.
<?php
function factorial(int $n) : int {
$return = 2;
for($i = 3; $i <= $n; ++$i) {
$return *= $i;
}
return $return;
}
function factorialr(int $n) : int {
if ($n === 2) { return 1; }
return factorialr($n - 1);
return $return;
}
// Note : checks on $n >= 1 are omitted here.
?>
See also Refactoring without tests should be fine, Refactoring Guru, PHP Refactoring: The Art of Improving Code Quality and Maintainability
Related : Test