Here's a sample code that I made up :
<?php
class RegisterController {
public $userRepo;
public $blogRepo;
public $mailer;
public $avatarRepo;
public function __construct(UserRepository $userRepo, AvatarRepository $avatarRepo, BlogRepository $blogRepo, Mailer $mailer) {
$this->userRepo = $userRepo;
$this->blogRepo = $blogRepo;
$this->mailer = $mailer;
$this->avatarRepo = $avatarRepo;
}
public function register(Request $request) {
$user = $this->userRepo->register($request);
$this->avatarRepo->uploadFor($user, $request->input('base64_avatar'));
$this->blogRepo->makeNewFor($user);
$this->mailer->sendRegisteredConfirmationTo($user);
}
}
It feels like my controller is doing too many things :
- Creates a user
- Upload the avatar and link it to the user
- Create a blog and link it to the user
- Send a mail to the user
But it also feels like my controller is only doing one thing here : "Registering a user".
In the same manner, what if the RegisterController now also has a unregister() method ? Is it going to violate the SRP ? Since one could say it'll then handle registering AND unregistering, but one could also say it'll still only handle the concept of registering.
Where is the line that says "the scope of this class or this method is too wide, there should be two classes/methods" ?