I'm running into problems breaking up a complex Controller.
The action has many different conditions and the code inside each block uses different dependencies. What's the most logical way to break this up into separate controllers so I have a better handle on my growing list of constructor dependencies?
The reason it's all in one action is because it's serving a single URL /report
which renders different templates based on permissions and other conditions.
PS. The code is not technically correct, was made quickly to visualise my question.
<?php
class ExampleController
{
protected $dependency1;
protected $dependency2;
protected $dependency3;
protected $user;
/**
* ExampleController constructor.
*
* @param $dependency1
* @param $dependency2
* @param $dependency3
* @param $user
*/
public function __construct($dependency1, $dependency2, $dependency3, $user)
{
$this->dependency1 = $dependency1;
$this->dependency2 = $dependency2;
$this->dependency3 = $dependency3;
$this->user = $user;
}
public function exampleAction()
{
if ($this->user->hasRole('a')) {
$this->dependency1->something();
} elseif ($this->user->hasRole('b')) {
$this->dependency2->something();
} elseif ($this->user->hasRole('c')) {
$this->dependency3->something();
}
}
}