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 |
||
| 17 | class Handler implements HandlerInterface |
||
| 18 | { |
||
| 19 | /** @var \eZ\Publish\Core\Persistence\Legacy\URL\Gateway */ |
||
| 20 | private $urlGateway; |
||
| 21 | |||
| 22 | /** @var \eZ\Publish\Core\Persistence\Legacy\URL\Mapper */ |
||
| 23 | private $urlMapper; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Handler constructor. |
||
| 27 | * |
||
| 28 | * @param \eZ\Publish\Core\Persistence\Legacy\URL\Gateway $gateway |
||
| 29 | * @param \eZ\Publish\Core\Persistence\Legacy\URL\Mapper $mapper |
||
| 30 | */ |
||
| 31 | public function __construct(Gateway $gateway, Mapper $mapper) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc} |
||
| 39 | */ |
||
| 40 | public function updateUrl($id, URLUpdateStruct $urlUpdateStruct) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc} |
||
| 54 | */ |
||
| 55 | public function find(URLQuery $query) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * {@inheritdoc} |
||
| 72 | */ |
||
| 73 | View Code Duplication | public function loadById($id) |
|
| 85 | |||
| 86 | /** |
||
| 87 | * {@inheritdoc} |
||
| 88 | */ |
||
| 89 | View Code Duplication | public function loadByUrl($url) |
|
| 101 | |||
| 102 | /** |
||
| 103 | * {@inheritdoc} |
||
| 104 | */ |
||
| 105 | public function findUsages($id) |
||
| 111 | } |
||
| 112 |