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 | abstract class MessagePartFactory |
||
18 | { |
||
19 | /** |
||
20 | * @var PartStreamFilterManagerFactory responsible for creating |
||
21 | * PartStreamFilterManager instances |
||
22 | */ |
||
23 | protected $partStreamFilterManagerFactory; |
||
24 | |||
25 | /** |
||
26 | * Initializes class dependencies. |
||
27 | * |
||
28 | * @param PartStreamFilterManagerFactory $psf |
||
29 | */ |
||
30 | public function __construct(PartStreamFilterManagerFactory $psf) |
||
34 | |||
35 | /** |
||
36 | * Returns the singleton instance for the class. |
||
37 | * |
||
38 | * @param PartStreamFilterManagerFactory $psf |
||
39 | * @param HeaderFactory $hf |
||
40 | * @param PartFilterFactory $pf |
||
41 | * @return MessagePartFactory |
||
42 | */ |
||
43 | View Code Duplication | public static function getInstance( |
|
55 | |||
56 | /** |
||
57 | * Constructs a new MessagePart object and returns it |
||
58 | * |
||
59 | * @param string $messageObjectId |
||
60 | * @param PartBuilder $partBuilder |
||
61 | * @return \ZBateson\MailMimeParser\Message\Part\MessagePart |
||
62 | */ |
||
63 | public abstract function newInstance($messageObjectId, PartBuilder $partBuilder); |
||
64 | } |
||
65 |
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.