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 |
||
26 | trait ClientTrait |
||
27 | { |
||
28 | private $session; |
||
29 | |||
30 | /** |
||
31 | * @see ClientInterface |
||
32 | */ |
||
33 | public function initialize(Session $session) |
||
37 | |||
38 | /** |
||
39 | * Most of the time, there is nothing to be done at shutdown. |
||
40 | * @see ClientInterface |
||
41 | */ |
||
42 | public function shutdown() |
||
45 | |||
46 | /** |
||
47 | * getSession |
||
48 | * |
||
49 | * All subclasses of Client have to use this method to access the session. |
||
50 | * |
||
51 | * @throws FoundationException if Session is not set. |
||
52 | * @return Session |
||
53 | */ |
||
54 | View Code Duplication | protected function getSession() |
|
67 | } |
||
68 |
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.