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 |
||
11 | final class CustomBlockContext implements Context |
||
12 | { |
||
13 | /** |
||
14 | * @var SharedStorageInterface |
||
15 | */ |
||
16 | private $sharedStorage; |
||
17 | |||
18 | /** |
||
19 | * @var ExampleFactoryInterface |
||
20 | */ |
||
21 | private $customBlockExampleFactory; |
||
22 | |||
23 | /** |
||
24 | * @var ObjectManager |
||
25 | */ |
||
26 | private $customBlockManager; |
||
27 | |||
28 | /** |
||
29 | * @param SharedStorageInterface $sharedStorage |
||
30 | * @param ExampleFactoryInterface $customBlockExampleFactory |
||
31 | * @param ObjectManager $customBlockManager |
||
32 | */ |
||
33 | public function __construct( |
||
42 | |||
43 | /** |
||
44 | * @Given the store has custom block :name |
||
45 | */ |
||
46 | View Code Duplication | public function theStoreHasCustomBlock($name) |
|
55 | |||
56 | /** |
||
57 | * @Given the store has custom block :name with body :body |
||
58 | */ |
||
59 | View Code Duplication | public function theStoreHasCustomBlockWithBody($name, $body) |
|
68 | |||
69 | /** |
||
70 | * @Given the store has custom block :name with title :title |
||
71 | */ |
||
72 | View Code Duplication | public function theStoreHasCustomBlockWithTitle($name, $title) |
|
81 | } |
||
82 |
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.