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 |
||
23 | View Code Duplication | class DeletePost implements ServiceInterface |
|
24 | { |
||
25 | /** |
||
26 | * @var AbstractPostRepository |
||
27 | */ |
||
28 | private $postRepository; |
||
29 | |||
30 | /** |
||
31 | * @var Post |
||
32 | */ |
||
33 | private $post; |
||
34 | |||
35 | /** |
||
36 | * @var LoggerInterface |
||
37 | */ |
||
38 | private $logger; |
||
39 | |||
40 | /** |
||
41 | * DeletePost constructor. |
||
42 | * @param AbstractPostRepository $postRepository |
||
43 | * @param Post $post |
||
44 | * @param LoggerInterface $logger |
||
45 | */ |
||
46 | 3 | public function __construct(AbstractPostRepository $postRepository, Post $post, LoggerInterface $logger) |
|
52 | |||
53 | /** |
||
54 | * @return boolean |
||
55 | */ |
||
56 | 3 | public function run(): bool |
|
66 | } |
||
67 |