In certain parts of my system, there are some selection filters, an example, is when selecting the general sector employees area, I can select:
Partners (all)
Active contributors (status = true)
Inactive contributors (status = false)
I can do this in two ways.
Via parameter in method:
public static function get_collaborators(string $filter = 'all')
{
if($filter == 'all'){
$sql = 'SELECT * FROM data_collaborators';
} elseif($filter == 'active'){
$sql = 'SELECT * FROM data_collaborators WHERE status = 1';
} elseif($filter == 'inactive'){
$sql = 'SELECT * FROM data_collaborators WHERE status = 0';
}
$rs = \MySQL\MySQLSelector::select_by_query_string($sql);
return $rs['data'];
}
Or, Via separate methods:
public static function get_all_collaborators()
{
$sql = 'SELECT * FROM data_collaborators';
$rs = \MySQL\MySQLSelector::select_by_query_string($sql);
return $rs['data'];
}
public static function get_active_collaborators()
{
$sql = 'SELECT * FROM data_collaborators WHERE status = "1"';
$rs = \MySQL\MySQLSelector::select_by_query_string($sql);
return $rs['data'];
}
public static function get_inactive_collaborators()
{
$sql = 'SELECT * FROM data_collaborators WHERE status = "0"';
$rs = \MySQL\MySQLSelector::select_by_query_string($sql);
return $rs['data'];
}
As far as I understand, the first mode (with parameters) would have less performance because it has checks, so several separate methods would be better.
The question is:
Is there a difference in running from one to another? (even if derisory) If so, which one would be better? If not, which one follows the 'correct standard' followed by the majority?
If there is another way, what would it be?