Refactoring model files
DishantK1807 opened this issue · comments
Dishant Khanna commented
Even after the previous refactoring done by @kamishettysreeja25, there are still many duplicate functions in the system which needs refactoring.
E.g.
User_model.php
function User_select_nick($nick) { return sql_num_query("SELECT * FROM `User` WHERE `Nick`='" . sql_escape($nick) . "' LIMIT 1"); } function User_select_mail($mail) { return sql_num_query("SELECT * FROM `User` WHERE `email`='" . sql_escape($mail) . "' LIMIT 1"); } //Their duplicate functions function count_user_by_nick($nick) { return sql_num_query("SELECT * FROM `User` WHERE `Nick`='" . sql_escape($nick) . "' LIMIT 1"); } function count_user_by_email($mail) { return sql_num_query("SELECT * FROM `User` WHERE `email`='" . sql_escape($mail) . "' LIMIT 1"); }
Similarly, there are many other functions in different model files as well.
We need to remove those functions and optimize the system, improve code quality.
Ujjwal Bhardwaj commented
Since these functions perform a single function of checking if the user exists or not, I was thinking we can replace them with a single function like,
doesUserExist($parameter, $value) {
//
}
which can then be used like,
if (doesUserExist("Nick", $nick)) { }
if (doesUserExist("email", $email)) { }