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 |
||
10 | class LikeSpec extends ObjectBehavior |
||
11 | { |
||
12 | private $field = 'foo'; |
||
13 | |||
14 | private $value = 'bar'; |
||
15 | |||
16 | public function let() |
||
20 | |||
21 | public function it_is_a_specification() |
||
25 | |||
26 | View Code Duplication | public function it_surrounds_with_wildcards_when_using_contains(QueryBuilder $qb, ArrayCollection $parameters) |
|
36 | |||
37 | View Code Duplication | public function it_starts_with_wildcard_when_using_ends_with(QueryBuilder $qb, ArrayCollection $parameters) |
|
47 | |||
48 | View Code Duplication | public function it_ends_with_wildcard_when_using_starts_with(QueryBuilder $qb, ArrayCollection $parameters) |
|
58 | } |
||
59 |
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.