Total Complexity | 7 |
Total Lines | 80 |
Duplicated Lines | 17.5 % |
Changes | 0 |
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 namespace Nord\Lumen\Elasticsearch\Search\Query\Joining; |
||
12 | class HasParentQuery extends AbstractQuery |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $type; |
||
19 | |||
20 | /** |
||
21 | * @var QueryDSL |
||
22 | */ |
||
23 | private $query; |
||
24 | |||
25 | |||
26 | /** |
||
27 | * @inheritdoc |
||
28 | */ |
||
29 | View Code Duplication | public function toArray() |
|
|
|||
30 | { |
||
31 | $hasParent = [ |
||
32 | 'parent_type' => $this->getType(), |
||
33 | 'query' => $this->getQuery()->toArray(), |
||
34 | ]; |
||
35 | |||
36 | $scoreMode = $this->getScoreMode(); |
||
37 | if (!is_null($scoreMode)) { |
||
38 | $hasParent['score_mode'] = $scoreMode; |
||
39 | } |
||
40 | |||
41 | return ['has_parent' => $hasParent]; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | protected function getValidScoreModes() |
||
48 | { |
||
49 | return [ |
||
50 | self::SCORE_MODE_SCORE, |
||
51 | self::SCORE_MODE_NONE |
||
52 | ]; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param string $type |
||
57 | * @return HasParentQuery |
||
58 | */ |
||
59 | public function setType($type) |
||
60 | { |
||
61 | $this->type = $type; |
||
62 | return $this; |
||
63 | } |
||
64 | |||
65 | |||
66 | /** |
||
67 | * @return string |
||
68 | */ |
||
69 | public function getType() |
||
70 | { |
||
71 | return $this->type; |
||
72 | } |
||
73 | |||
74 | |||
75 | /** |
||
76 | * @param QueryDSL $query |
||
77 | * @return HasParentQuery |
||
78 | */ |
||
79 | public function setQuery(QueryDSL $query) |
||
83 | } |
||
84 | |||
85 | |||
86 | /** |
||
87 | * @return QueryDSL |
||
88 | */ |
||
89 | public function getQuery() |
||
92 | } |
||
93 | } |
||
94 |
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.