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 |
||
16 | class AccountFactory |
||
17 | { |
||
18 | /** |
||
19 | * @var Format[] Possible formats used when parsing account |
||
20 | */ |
||
21 | private $formats; |
||
22 | |||
23 | /** |
||
24 | * @var RewriterStrategy[] Strategies for rewriting failing account numbers |
||
25 | */ |
||
26 | private $rewrites; |
||
27 | |||
28 | /** |
||
29 | * @var bool Flag if rewrites should be allowed when creating account objects |
||
30 | */ |
||
31 | private $allowRewrites; |
||
32 | |||
33 | /** |
||
34 | * @var UnknownFormat The unknown format or null if unknown is disallowed |
||
35 | */ |
||
36 | private $unknownFormat; |
||
37 | |||
38 | /** |
||
39 | * @var RewriterStrategy[] Preprocessors used to alter account before parsing starts |
||
40 | */ |
||
41 | private $preprocessors; |
||
42 | |||
43 | /** |
||
44 | * @param Format[] $formats Possible formats used when parsing account |
||
45 | * @param RewriterStrategy[] $rewrites Rewrites used if parsed the raw account number fails |
||
46 | * @param boolean $allowRewrites Flag if rewrites should be allowed when creating account objects |
||
47 | * @param boolean $allowUnknown Flag if the unknown account format should be used |
||
48 | 110 | * @param RewriterStrategy[] $preprocessors Preprocessors used to alter account before parsing starts |
|
49 | */ |
||
50 | public function __construct( |
||
63 | |||
64 | /** |
||
65 | * Enable formats |
||
66 | * |
||
67 | * Please note that formats not listed will be dropped and |
||
68 | * can not be recovered. |
||
69 | * |
||
70 | * @param string[] $formats List of formats to whitelist |
||
71 | 1 | * @return null |
|
72 | */ |
||
73 | 1 | public function whitelistFormats(array $formats) |
|
81 | |||
82 | /** |
||
83 | * Disable formats |
||
84 | * |
||
85 | * Please note that listed formats will be dropped and |
||
86 | * can not be recovered. |
||
87 | * |
||
88 | * @param string[] $formats List of formats to blacklist |
||
89 | 100 | * @return null |
|
90 | */ |
||
91 | 100 | public function blacklistFormats(array $formats) |
|
97 | |||
98 | /** |
||
99 | * Create bank account object using number |
||
100 | * |
||
101 | * @param string $number |
||
102 | * @return AccountNumber |
||
103 | 110 | * @throws UnableToCreateAccountException If unable to create |
|
104 | */ |
||
105 | 110 | public function createAccount($number) |
|
214 | } |
||
215 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..