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 declare(strict_types=1); |
||
18 | class DragonController |
||
19 | { |
||
20 | /** @var ViewEngine $view */ |
||
21 | private $view; |
||
22 | |||
23 | /** @var DragonService $service */ |
||
24 | private $service; |
||
25 | |||
26 | /** |
||
27 | * DragonController constructor. |
||
28 | * @param DragonService $service |
||
29 | */ |
||
30 | public function __construct(ViewEngine $view, DragonService $service) |
||
35 | |||
36 | /** |
||
37 | * @param ServerRequestInterface $request |
||
38 | * @param array $args |
||
39 | * @return ResponseInterface |
||
40 | */ |
||
41 | public function indexAction(ServerRequestInterface $request, array $args): ResponseInterface |
||
52 | |||
53 | /** |
||
54 | * @param ServerRequestInterface $request |
||
55 | * @param array $args |
||
56 | * @return ResponseInterface |
||
57 | * @throws \Doctrine\ORM\EntityNotFoundException |
||
58 | */ |
||
59 | public function viewAction(ServerRequestInterface $request, array $args): ResponseInterface |
||
70 | |||
71 | /** |
||
72 | * @param ServerRequestInterface $request |
||
73 | * @param array $args |
||
74 | * @return ResponseInterface |
||
75 | * @throws \Doctrine\ORM\ORMException |
||
76 | * @throws \Doctrine\ORM\OptimisticLockException |
||
77 | */ |
||
78 | public function createAction(ServerRequestInterface $request, array $args): ResponseInterface |
||
104 | |||
105 | /** |
||
106 | * @param ServerRequestInterface $request |
||
107 | * @param array $args |
||
108 | * @return ResponseInterface |
||
109 | * @throws \Doctrine\ORM\ORMException |
||
110 | * @throws \Doctrine\ORM\OptimisticLockException |
||
111 | */ |
||
112 | public function editAction(ServerRequestInterface $request, array $args): ResponseInterface |
||
143 | |||
144 | /** |
||
145 | * @param ServerRequestInterface $request |
||
146 | * @param array $args |
||
147 | * @return ResponseInterface |
||
148 | * @throws \Doctrine\ORM\ORMException |
||
149 | * @throws \Doctrine\ORM\OptimisticLockException |
||
150 | */ |
||
151 | public function deleteAction(ServerRequestInterface $request, array $args): ResponseInterface |
||
181 | |||
182 | /** |
||
183 | * @param string $message |
||
184 | * @param string $class |
||
185 | * @return bool|string |
||
186 | */ |
||
187 | private function alertBox(string $message, string $class = ''): string |
||
194 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.