| Conditions | 29 |
| Paths | 53 |
| Total Lines | 96 |
| Code Lines | 85 |
| Lines | 96 |
| Ratio | 100 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 116 | View Code Duplication | protected function setReferences($item, $step) |
|
| 117 | { |
||
| 118 | if (!array_key_exists('references', $step->dsl)) { |
||
| 119 | return false; |
||
| 120 | } |
||
| 121 | |||
| 122 | $references = $this->setReferencesCommon($item, $step->dsl['references']); |
||
| 123 | $item = $this->insureSingleEntity($item, $references); |
||
| 124 | |||
| 125 | foreach ($references as $reference) { |
||
| 126 | switch ($reference['attribute']) { |
||
| 127 | // a trashed item extends a location, so in theory everything 'location' here should work |
||
| 128 | case 'location_id': |
||
| 129 | case 'id': |
||
| 130 | $value = $item->id; |
||
| 131 | break; |
||
| 132 | case 'remote_id': |
||
| 133 | case 'location_remote_id': |
||
| 134 | $value = $item->remoteId; |
||
| 135 | break; |
||
| 136 | case 'always_available': |
||
| 137 | $value = $item->contentInfo->alwaysAvailable; |
||
| 138 | break; |
||
| 139 | case 'content_id': |
||
| 140 | $value = $item->contentId; |
||
| 141 | break; |
||
| 142 | case 'content_type_id': |
||
| 143 | $value = $item->contentInfo->contentTypeId; |
||
| 144 | break; |
||
| 145 | case 'content_type_identifier': |
||
| 146 | $contentTypeService = $this->repository->getContentTypeService(); |
||
| 147 | $value = $contentTypeService->loadContentType($item->contentInfo->contentTypeId)->identifier; |
||
| 148 | break; |
||
| 149 | case 'current_version': |
||
| 150 | case 'current_version_no': |
||
| 151 | $value = $item->contentInfo->currentVersionNo; |
||
| 152 | break; |
||
| 153 | case 'depth': |
||
| 154 | $value = $item->depth; |
||
| 155 | break; |
||
| 156 | case 'is_hidden': |
||
| 157 | $value = $item->hidden; |
||
| 158 | break; |
||
| 159 | case 'main_location_id': |
||
| 160 | $value = $item->contentInfo->mainLocationId; |
||
| 161 | break; |
||
| 162 | case 'main_language_code': |
||
| 163 | $value = $item->contentInfo->mainLanguageCode; |
||
| 164 | break; |
||
| 165 | case 'modification_date': |
||
| 166 | $value = $item->contentInfo->modificationDate->getTimestamp(); |
||
| 167 | break; |
||
| 168 | case 'name': |
||
| 169 | $value = $item->contentInfo->name; |
||
| 170 | break; |
||
| 171 | case 'owner_id': |
||
| 172 | $value = $item->contentInfo->ownerId; |
||
| 173 | break; |
||
| 174 | case 'parent_location_id': |
||
| 175 | $value = $item->parentLocationId; |
||
| 176 | break; |
||
| 177 | case 'path': |
||
| 178 | $value = $item->pathString; |
||
| 179 | break; |
||
| 180 | case 'priority': |
||
| 181 | $value = $item->priority; |
||
| 182 | break; |
||
| 183 | case 'publication_date': |
||
| 184 | $value = $item->contentInfo->publishedDate->getTimestamp(); |
||
| 185 | break; |
||
| 186 | case 'section_id': |
||
| 187 | $value = $item->contentInfo->sectionId; |
||
| 188 | break; |
||
| 189 | case 'section_identifier': |
||
| 190 | $sectionService = $this->repository->getSectionService(); |
||
| 191 | $value = $sectionService->loadSection($item->contentInfo->sectionId)->identifier; |
||
| 192 | break; |
||
| 193 | case 'sort_field': |
||
| 194 | $value = $this->sortConverter->sortField2Hash($item->sortField); |
||
| 195 | break; |
||
| 196 | case 'sort_order': |
||
| 197 | $value = $this->sortConverter->sortOrder2Hash($item->sortOrder); |
||
| 198 | break; |
||
| 199 | default: |
||
| 200 | throw new \InvalidArgumentException('Trash Manager does not support setting references for attribute ' . $reference['attribute']); |
||
| 201 | } |
||
| 202 | |||
| 203 | $overwrite = false; |
||
| 204 | if (isset($reference['overwrite'])) { |
||
| 205 | $overwrite = $reference['overwrite']; |
||
| 206 | } |
||
| 207 | $this->referenceResolver->addReference($reference['identifier'], $value, $overwrite); |
||
| 208 | } |
||
| 209 | |||
| 210 | return true; |
||
| 211 | } |
||
| 212 | } |
||
| 213 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.