mirror of
https://github.com/jupeter/clean-code-php.git
synced 2025-09-27 14:38:59 +02:00
Merge pull request #33 from peter-gribanov/encapsulate_conditionals2
Encapsulate conditionals
This commit is contained in:
13
README.md
13
README.md
@@ -585,22 +585,21 @@ $singleton = Configuration::getInstance();
|
|||||||
### Encapsulate conditionals
|
### Encapsulate conditionals
|
||||||
|
|
||||||
**Bad:**
|
**Bad:**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
if ($fsm->state === 'fetching' && is_empty($listNode)) {
|
if ($article->state === 'published') {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Good**:
|
**Good**:
|
||||||
```php
|
|
||||||
function shouldShowSpinner($fsm, $listNode) {
|
|
||||||
return $fsm->state === 'fetching' && is_empty($listNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldShowSpinner($fsmInstance, $listNodeInstance)) {
|
```php
|
||||||
// ...
|
if ($article->isPublished()) {
|
||||||
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**[⬆ back to top](#table-of-contents)**
|
**[⬆ back to top](#table-of-contents)**
|
||||||
|
|
||||||
### Avoid negative conditionals
|
### Avoid negative conditionals
|
||||||
|
Reference in New Issue
Block a user