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 | View Code Duplication | class Concurrency |
|
| 8 | { |
||
| 9 | use EnsureIsIntegerTrait; |
||
| 10 | use EnsureIsGreaterThanTrait; |
||
| 11 | |||
| 12 | const CONCURRENCY_IS_NOT_AN_INTEGER = 1; |
||
| 13 | const CONCURRENCY_IS_TOO_SMALL = 2; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var int |
||
| 17 | */ |
||
| 18 | private $concurrency; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param int $concurrency |
||
| 22 | */ |
||
| 23 | public function __construct($concurrency) |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @return int |
||
| 32 | */ |
||
| 33 | public function asInteger() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param mixed $concurrency |
||
| 40 | */ |
||
| 41 | private function ensureConcurrency($concurrency) |
||
| 56 | } |
||
| 57 |