Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Code refactoring is the process of restructuring and improving existing code without changing its external behavior. Refactoring allows us to slowly improve our code as we continue to add features. The goals when refactoring are: make the code easier to read, reduce complexity and improve maintainability.
Links
Refactor vs Rewrite
Modernize Your Legacy PHP Application
Example Code
<?php
function full_catalog_array($limit = null, $offset = 0) {
include("connection.php");
try {
$results = $db->query("SELECT title, category, img FROM Media");
} catch (Exception $e) {
echo "Unable to retrieved results";
exit;
}
$catalog = $results->fetchAll(PDO::FETCH_ASSOC);
return $catalog;
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up