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

Ignore some case for EarlyExit rule #259

Open
VincentLanglet opened this issue Aug 11, 2021 · 1 comment
Open

Ignore some case for EarlyExit rule #259

VincentLanglet opened this issue Aug 11, 2021 · 1 comment

Comments

@VincentLanglet
Copy link

I have the following method

public function foo(Collection $collection)
{
     $collection->add($this->bar);
     $collection->add($this->bar);

     if ($collection instanceof BOOM) {
          $collection->add($this->some)
     }
}

which reports an error because I didn't use an early exit.

But changing

     if ($collection instanceof BOOM) {
          $collection->add($this->some)
     }

to

     if (! $collection instanceof BOOM) {
          return;
     }

     $collection->add($this->some)

is taking more lines and not really reducing complexity.

Also, I may change later to

public function foo(Collection $collection)
{
     $collection->add($this->bar);
     $collection->add($this->bar);

     if ($collection instanceof Boom) {
          $collection->add($this->some)
     }

     if ($collection instanceof Please) {
          $collection->add($this->thanks)
     }
}

and so on.

The slevomat Early Exit standard has some configuration available
https://github.com/slevomat/coding-standard#slevomatcodingstandardcontrolstructuresearlyexit-

I would say it's better to use some.

@simPod
Copy link
Contributor

simPod commented Aug 12, 2021

I had no idea it had any configuration. Right now I do this 🙃

public function foo(Collection $collection)
{
     $collection->add($this->bar);
     $collection->add($this->bar);

     if ($collection instanceof BOOM) {
          $collection->add($this->some)
     }

     return;
}

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