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 |
||
28 | class Processes |
||
29 | { |
||
30 | /** |
||
31 | * Namespace factory. |
||
32 | * |
||
33 | * @var ResourceNamespaceFactory |
||
34 | */ |
||
35 | protected $namespace_factory; |
||
36 | |||
37 | /** |
||
38 | * Process factory. |
||
39 | * |
||
40 | * @var ProcessFactory |
||
41 | */ |
||
42 | protected $process_factory; |
||
43 | |||
44 | /** |
||
45 | * Acl. |
||
46 | * |
||
47 | * @var Acl |
||
48 | */ |
||
49 | protected $acl; |
||
50 | |||
51 | /** |
||
52 | * Log factory. |
||
53 | * |
||
54 | * @var LogFactory |
||
55 | */ |
||
56 | protected $log_factory; |
||
57 | |||
58 | /** |
||
59 | * Init. |
||
60 | */ |
||
61 | public function __construct(ProcessFactory $process_factory, Acl $acl, ResourceNamespaceFactory $namespace_factory, LogFactory $log_factory) |
||
68 | |||
69 | /** |
||
70 | * Entrypoint. |
||
71 | */ |
||
72 | View Code Duplication | public function getAll(ServerRequestInterface $request, Identity $identity, string $namespace): ResponseInterface |
|
91 | |||
92 | /** |
||
93 | * Entrypoint. |
||
94 | */ |
||
95 | View Code Duplication | public function getOne(ServerRequestInterface $request, Identity $identity, string $namespace, ObjectId $process): ResponseInterface |
|
102 | |||
103 | /** |
||
104 | * Force trigger process. |
||
105 | */ |
||
106 | View Code Duplication | public function post(ServerRequestInterface $request, Identity $identity, string $namespace): ResponseInterface |
|
121 | |||
122 | /** |
||
123 | * Stop process. |
||
124 | */ |
||
125 | View Code Duplication | public function delete(ServerRequestInterface $request, Identity $identity, string $namespace, ObjectId $process): ResponseInterface |
|
132 | |||
133 | /** |
||
134 | * Entrypoint. |
||
135 | */ |
||
136 | View Code Duplication | public function getAllLogs(ServerRequestInterface $request, Identity $identity, string $namespace, string $process): ResponseInterface |
|
171 | |||
172 | /** |
||
173 | * Entrypoint. |
||
174 | */ |
||
175 | public function getOneLog(ServerRequestInterface $request, Identity $identity, string $namespace, string $process, ObjectIdInterface $log): ResponseInterface |
||
181 | } |
||
182 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.