Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit number of lines within an if or for(each) loop? #98

Open
bmitch opened this issue Aug 4, 2017 · 1 comment
Open

Limit number of lines within an if or for(each) loop? #98

bmitch opened this issue Aug 4, 2017 · 1 comment

Comments

@bmitch
Copy link
Owner

bmitch commented Aug 4, 2017

No description provided.

@Exadra37
Copy link

Exadra37 commented Aug 5, 2017

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
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants