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 |
||
14 | class ConstraintRepositoryLookup implements ConstraintLookup { |
||
15 | |||
16 | /** @var ILoadBalancer */ |
||
17 | private $lb; |
||
18 | |||
19 | /** @var string|false */ |
||
20 | private $dbName; |
||
21 | |||
22 | /** |
||
23 | * @param ILoadBalancer $lb Load balancer for database connections. |
||
24 | * Must match $dbName, i.e. if $dbName is not false, |
||
25 | * then using the main DBLoadBalancer service may be incorrect. |
||
26 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
||
27 | */ |
||
28 | public function __construct( ILoadBalancer $lb, $dbName ) { |
||
32 | |||
33 | /** |
||
34 | * @param PropertyId $propertyId |
||
35 | * |
||
36 | * @return Constraint[] |
||
37 | */ |
||
38 | View Code Duplication | public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
49 | |||
50 | /** |
||
51 | * @param IResultWrapper $results |
||
52 | * |
||
53 | * @return Constraint[] |
||
54 | */ |
||
55 | private function convertToConstraints( IResultWrapper $results ) { |
||
81 | |||
82 | } |
||
83 |
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.