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 |
||
| 13 | class ContentMatcher extends AbstractMatcher |
||
| 14 | { |
||
| 15 | const MATCH_CONTENT_ID = 'content_id'; |
||
| 16 | const MATCH_LOCATION_ID = 'location_id'; |
||
| 17 | const MATCH_CONTENT_REMOTE_ID = 'content_remote_id'; |
||
| 18 | const MATCH_LOCATION_REMOTE_ID = 'location_remote_id'; |
||
| 19 | const MATCH_PARENT_LOCATION_ID = 'parent_location_id'; |
||
| 20 | const MATCH_PARENT_LOCATION_REMOTE_ID = 'parent_location_remote_id'; |
||
| 21 | const MATCH_CONTENT_TYPE_IDENTIFIER = 'content_type'; |
||
| 22 | |||
| 23 | protected $allowedConditions = array( |
||
| 24 | self::MATCH_CONTENT_ID, self::MATCH_LOCATION_ID, self::MATCH_CONTENT_REMOTE_ID, self::MATCH_LOCATION_REMOTE_ID, |
||
| 25 | self::MATCH_PARENT_LOCATION_ID, self::MATCH_PARENT_LOCATION_REMOTE_ID, self::MATCH_CONTENT_TYPE_IDENTIFIER |
||
| 26 | ); |
||
| 27 | protected $returns = 'Content'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param array $conditions key: condition, value: int / string / int[] / string[] |
||
| 31 | * @return ContentCollection |
||
| 32 | */ |
||
| 33 | public function match(array $conditions) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param array $conditions key: condition, value: int / string / int[] / string[] |
||
| 40 | * @return ContentCollection |
||
| 41 | */ |
||
| 42 | public function matchContent(array $conditions) |
||
| 76 | |||
| 77 | |||
| 78 | /** |
||
| 79 | * @param int[] $contentIds |
||
| 80 | * @return Content[] |
||
| 81 | */ |
||
| 82 | protected function findContentsByContentIds(array $contentIds) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param string[] $remoteContentIds |
||
| 95 | * @return Content[] |
||
| 96 | */ |
||
| 97 | protected function findContentsByContentRemoteIds(array $remoteContentIds) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param int[] $locationIds |
||
| 110 | * @return Content[] |
||
| 111 | */ |
||
| 112 | View Code Duplication | protected function findContentsByLocationIds(array $locationIds) |
|
| 123 | |||
| 124 | /** |
||
| 125 | * @param string[] $remoteLocationIds |
||
| 126 | * @return Content[] |
||
| 127 | */ |
||
| 128 | View Code Duplication | protected function findContentsByLocationRemoteIds($remoteLocationIds) |
|
| 139 | |||
| 140 | /** |
||
| 141 | * @param int[] $parentLocationIds |
||
| 142 | * @return Content[] |
||
| 143 | */ |
||
| 144 | View Code Duplication | protected function findContentsByParentLocationIds($parentLocationIds) |
|
| 158 | |||
| 159 | /** |
||
| 160 | * @param string[] $remoteParentLocationIds |
||
| 161 | * @return Content[] |
||
| 162 | */ |
||
| 163 | View Code Duplication | protected function findContentsByParentLocationRemoteIds($remoteParentLocationIds) |
|
| 174 | |||
| 175 | /** |
||
| 176 | * @param string[] $contentTypeIdentifiers |
||
| 177 | * @return Content[] |
||
| 178 | */ |
||
| 179 | View Code Duplication | protected function findContentsByContentTypeIdentifiers(array $contentTypeIdentifiers) |
|
| 193 | } |
||
| 194 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.