Limit number of lines within an if or for(each) loop?
bmitch opened this issue · comments
Bill Mitchell commented
Paulo Renato commented
Also While loops should be considered here.
Any logic inside this loops structures should be abstracted to their own methods or classes and a meaningful name must be chosen to explicitly represent what is being abstracted.
<?php
class UserHandler
{
private $userRepo;
public function __construct(UserRepositoryContract $userRepo)
{
$this->userRepo = $userRepo;
}
public function getUsersFeedbackRate()
{
foreach ($this->userRepo->all() as $user) {
$this->calculateUserFeedbackRate($user);
}
}
private function calculateUserFeedbackRate(UserValues $user)
{
// Use the User Values immutable object to get the data about the user and perform your logic
}
}