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 |
||
| 5 | class Offer_Structured_Data { |
||
| 6 | |||
| 7 | /** |
||
| 8 | * @var Shipping_Zones |
||
| 9 | */ |
||
| 10 | private $shipping_zones; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Offer_Structured_Data constructor. |
||
| 14 | * |
||
| 15 | * @param Shipping_Zones $shipping_zones |
||
| 16 | */ |
||
| 17 | public function __construct( $shipping_zones ) { |
||
| 24 | |||
| 25 | public function entity_jsonld( $jsonld, $post_id ) { |
||
| 45 | |||
| 46 | } |
||
| 47 |
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.