I've created some controller for handling clicked links statistics. Does this class meet Single Responsibility Principle?
class StatisticsController
{
protected $statisticsQuery;
public function __construct(StatisticsQuery $statisticsQuery)
{
$this->statisticsQuery = $statisticsQuery;
}
public function recordClickedLink(array $request)
{
(...)
if ($this->canRecordClick()) {
// record clicked link
}
(...)
}
public function getStatistics(array $request)
{
(...)
$someRequestParam = $request['id'];
$statistics = $this->statisticsQuery->get($someRequestParam);
(...)
}
protected function canRecordClick()
{
// returns true of false
}
}
If has two public methods. The first is responsible for saving clicked link to a database by delegating it to a model class. The second public method is responsible for getting statistics and it is the only method which use $statisticsQuery
object passed to a class' constructor. Is it OK that recordClickedLink
method doesn't need constructor's argument?
I wonder also if it is OK that my class contain canRecordClick
method with logic for checking if link click can be saved during particular request.
If this class doesn't meet SRP, how can I refactor it?