doctrine / doctrine/coding-standard

Ignore some case for EarlyExit rule

Open
#259 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
PHP
Stars
320
Forks
50
PR merge metrics
No merged PRs in 30d

Description

I have the following method
```php
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
```php
if ($collection instanceof BOOM) {
$collection->add($this->some)
}
```
to
```php
if (! $collection instanceof BOOM) {
return;
}

$collection->add($this->some)
```
is taking more lines and not really reducing complexity.

Also, I may change later to
```php
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/blob/master/doc/control-structures.md#slevomatcodingstandardcontrolstructuresearlyexit-

I would say it's better to use some.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.