Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 7 | class Memcached extends CheckDefinition |
||
| 8 | { |
||
| 9 | public $command = 'service memcached status'; |
||
| 10 | |||
| 11 | public function resolve(Process $process) |
||
| 12 | { |
||
| 13 | if (str_contains($process->getOutput(), 'memcached is running')) || (str_contains($process->getOutput(), 'active (running)') ) { |
||
|
|
|||
| 14 | $this->check->succeed('is running'); |
||
| 15 | |||
| 16 | return; |
||
| 17 | } |
||
| 18 | |||
| 19 | $this->check->fail('is not running'); |
||
| 20 | } |
||
| 21 | } |
||
| 22 |