1
0
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:
Tomáš Votruba
2017-08-31 19:49:18 +02:00
committed by GitHub

View File

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