2
In a controller called activities, I have a method called reminder.
This method, receives an id, looks for that activity based on that id and sends an email to the moderator of that activity with data from it.
This method is with 'too many responsibilities'?
I am sending two methods to already join another doubt. By code designer, which one is correct? What sends separates $client into a variable (reminder_a), or what always uses $Activity to refer to clients (reminder_b)?
Follows method:
/**
* Send the remember email with a resource
* @param int $id
*/
public function reminder_a($id)
{
$activity = $this->activities->getById($id);
$client = $activity->client;
$title = 'Reminder of activity ' . $activity->name;
$view = 'emails.activity.reminder';
$data = ['activity' => $activity, 'cliente' => $client];
CustomMail::sendBasicMail($view, $title, $activity->client->email, $data);
}
/**
* Send the remember email with a resource
* @param int $id
*/
public function reminder_b($id)
{
$activity = $this->activities->getById($id);
$title = 'Reminder of activity ' . $activity->name;
$view = 'emails.activity.reminder';
CustomMail::sendBasicMail($view, $title, $activity->client->email, $activity);
}
Perfect @Rodrigo. About encapsulating email, how I would pass information like: the view to be used, custom title and etc, if I don’t call it in the method where I did the activity query?
– Rafael Soufraz
If you observe, I can use sendBasicMail for any type of email.
– Rafael Soufraz
If the
SendBasicMail
already encapsulates well the task of sending emails, maybe putting another layer of abstraction (for example, a service) is not so necessary. But what I would do, for example, would be to create a methodsendActivityEmail
, to which you would pass the activity or simply the$id
of it. (in that case it would be necessary to inject the activity repository as a dependency of the email sending service).– Rodrigo Rigotti
Hmm.. Today my system sends on average 24 different types of emails. There would be a way for each one? :/
– Rafael Soufraz
That’s a matter of style. As I like to have several methods in which each one performs a certain type of task (and not a single generic task), I would do it. There goes much of the will of the developer. :)
– Rodrigo Rigotti
There is relativity in that right? A repository for example. You wouldn’t create a method for each different query. : p
– Rafael Soufraz
Of course not, you group according to the parameters of the methods up to an acceptable state :)
– Rodrigo Rigotti
Thanks @Rodrigo. The discussion was very productive and cleared my question.
– Rafael Soufraz