| Conditions | 2 |
| Paths | 2 |
| Total Lines | 54 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 30 | public function visit(Visitor $visitor, Generator $generator, $data) |
||
| 31 | { |
||
| 32 | $generator->startObjectElement('Relation'); |
||
| 33 | $visitor->setHeader('Content-Type', $generator->getMediaType('Relation')); |
||
| 34 | |||
| 35 | $generator->startAttribute( |
||
| 36 | 'href', |
||
| 37 | $this->router->generate( |
||
| 38 | 'ezpublish_rest_loadVersionRelation', |
||
| 39 | array( |
||
| 40 | 'contentId' => $data->contentId, |
||
| 41 | 'versionNumber' => $data->versionNo, |
||
| 42 | 'relationId' => $data->relation->id, |
||
| 43 | ) |
||
| 44 | ) |
||
| 45 | ); |
||
| 46 | $generator->endAttribute('href'); |
||
| 47 | |||
| 48 | $generator->startObjectElement('SourceContent', 'ContentInfo'); |
||
| 49 | $generator->startAttribute( |
||
| 50 | 'href', |
||
| 51 | $this->router->generate( |
||
| 52 | 'ezpublish_rest_loadContent', |
||
| 53 | array( |
||
| 54 | 'contentId' => $data->contentId, |
||
| 55 | ) |
||
| 56 | ) |
||
| 57 | ); |
||
| 58 | $generator->endAttribute('href'); |
||
| 59 | $generator->endObjectElement('SourceContent'); |
||
| 60 | |||
| 61 | $generator->startObjectElement('DestinationContent', 'ContentInfo'); |
||
| 62 | $generator->startAttribute( |
||
| 63 | 'href', |
||
| 64 | $this->router->generate( |
||
| 65 | 'ezpublish_rest_loadContent', |
||
| 66 | array( |
||
| 67 | 'contentId' => $data->relation->getDestinationContentInfo()->id, |
||
| 68 | ) |
||
| 69 | ) |
||
| 70 | ); |
||
| 71 | $generator->endAttribute('href'); |
||
| 72 | $generator->endObjectElement('DestinationContent'); |
||
| 73 | |||
| 74 | if ($data->relation->sourceFieldDefinitionIdentifier !== null) { |
||
| 75 | $generator->startValueElement('SourceFieldDefinitionIdentifier', $data->relation->sourceFieldDefinitionIdentifier); |
||
| 76 | $generator->endValueElement('SourceFieldDefinitionIdentifier'); |
||
| 77 | } |
||
| 78 | |||
| 79 | $generator->startValueElement('RelationType', $this->getRelationTypeString($data->relation->type)); |
||
| 80 | $generator->endValueElement('RelationType'); |
||
| 81 | |||
| 82 | $generator->endObjectElement('Relation'); |
||
| 83 | } |
||
| 84 | |||
| 108 |