fossasia / engelsystem

Shift planning system for events.

Home Page:http://engelsystem.de

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Refactoring model files

DishantK1807 opened this issue · comments

#196

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.

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)) { }