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 |
||
15 | class Feature |
||
16 | { |
||
17 | |||
18 | const RESOURCE_COLLECTION = 'features'; |
||
19 | const RESOURCE_REPLACE = '{account_id}'; |
||
20 | |||
21 | /** @var TwitterAds $twitterAds */ |
||
22 | private $twitterAds; |
||
23 | |||
24 | /** |
||
25 | * Feature constructor. |
||
26 | * @param TwitterAds $twitterAds |
||
27 | */ |
||
28 | public function __construct(TwitterAds $twitterAds) |
||
33 | |||
34 | View Code Duplication | protected static function assureApi(TwitterAds $instance = null) |
|
44 | |||
45 | /** |
||
46 | * Returns a Cursor instance for a given resource. |
||
47 | * |
||
48 | * @param $params |
||
49 | * |
||
50 | * @return Cursor |
||
51 | */ |
||
52 | View Code Duplication | public function all($params = []) |
|
59 | |||
60 | /** |
||
61 | * @return TwitterAds |
||
62 | */ |
||
63 | public function getTwitterAds() |
||
67 | } |
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.