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 |
||
9 | class StepDependencyGraphBuilder implements GraphBuilderInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var StepRegistration[] |
||
13 | */ |
||
14 | private $steps; |
||
15 | |||
16 | /** |
||
17 | * @var StepRegistration[] |
||
18 | */ |
||
19 | private $idToStep = []; |
||
20 | |||
21 | /** |
||
22 | * The actual graph maintained as an array of arrays (node id to successor ids). |
||
23 | * |
||
24 | * @var [][] |
||
25 | */ |
||
26 | private $idDirectedGraph = []; |
||
27 | |||
28 | /** |
||
29 | * @param StepRegistration[] $steps |
||
30 | */ |
||
31 | 12 | public function __construct($steps) |
|
35 | |||
36 | /** |
||
37 | * @return DependencyGraph |
||
38 | */ |
||
39 | 11 | public function build() |
|
55 | |||
56 | /** |
||
57 | * @param StepRegistration $currentStep |
||
58 | * |
||
59 | * @throws PipelineBuildingException |
||
60 | */ |
||
61 | 11 | View Code Duplication | private function addBeforesToDirectedGraph(StepRegistration $currentStep) |
76 | |||
77 | /** |
||
78 | * @param StepRegistration $currentStep |
||
79 | * |
||
80 | * @throws PipelineBuildingException |
||
81 | */ |
||
82 | 10 | View Code Duplication | private function addAftersToDirectedGraph(StepRegistration $currentStep) |
97 | } |
||
98 |