| Conditions | 2 |
| Paths | 2 |
| Total Lines | 106 |
| Code Lines | 73 |
| 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 |
||
| 49 | protected function visitLocationAttributes(Visitor $visitor, Generator $generator, LocationValue $location) |
||
| 50 | { |
||
| 51 | $generator->startAttribute( |
||
| 52 | 'href', |
||
| 53 | $this->router->generate( |
||
| 54 | 'ezpublish_rest_loadLocation', |
||
| 55 | array('locationPath' => trim($location->pathString, '/')) |
||
| 56 | ) |
||
| 57 | ); |
||
| 58 | $generator->endAttribute('href'); |
||
| 59 | |||
| 60 | $generator->startValueElement('id', $location->id); |
||
| 61 | $generator->endValueElement('id'); |
||
| 62 | |||
| 63 | $generator->startValueElement('priority', $location->priority); |
||
| 64 | $generator->endValueElement('priority'); |
||
| 65 | |||
| 66 | $generator->startValueElement( |
||
| 67 | 'hidden', |
||
| 68 | $this->serializeBool($generator, $location->hidden) |
||
| 69 | ); |
||
| 70 | $generator->endValueElement('hidden'); |
||
| 71 | |||
| 72 | $generator->startValueElement( |
||
| 73 | 'invisible', |
||
| 74 | $this->serializeBool($generator, $location->invisible) |
||
| 75 | ); |
||
| 76 | $generator->endValueElement('invisible'); |
||
| 77 | |||
| 78 | $generator->startObjectElement('ParentLocation', 'Location'); |
||
| 79 | if (trim($location->pathString, '/') !== '1') { |
||
| 80 | $generator->startAttribute( |
||
| 81 | 'href', |
||
| 82 | $this->router->generate( |
||
| 83 | 'ezpublish_rest_loadLocation', |
||
| 84 | array( |
||
| 85 | 'locationPath' => implode('/', array_slice($location->path, 0, count($location->path) - 1)), |
||
| 86 | ) |
||
| 87 | ) |
||
| 88 | ); |
||
| 89 | $generator->endAttribute('href'); |
||
| 90 | } |
||
| 91 | $generator->endObjectElement('ParentLocation'); |
||
| 92 | |||
| 93 | $generator->startValueElement('pathString', $location->pathString); |
||
| 94 | $generator->endValueElement('pathString'); |
||
| 95 | |||
| 96 | $generator->startValueElement('depth', $location->depth); |
||
| 97 | $generator->endValueElement('depth'); |
||
| 98 | |||
| 99 | $generator->startValueElement('childCount', $this->locationService->getLocationChildCount($location)); |
||
| 100 | $generator->endValueElement('childCount'); |
||
| 101 | |||
| 102 | $generator->startValueElement('remoteId', $location->remoteId); |
||
| 103 | $generator->endValueElement('remoteId'); |
||
| 104 | |||
| 105 | $generator->startObjectElement('Children', 'LocationList'); |
||
| 106 | $generator->startAttribute( |
||
| 107 | 'href', |
||
| 108 | $this->router->generate( |
||
| 109 | 'ezpublish_rest_loadLocationChildren', |
||
| 110 | array( |
||
| 111 | 'locationPath' => trim($location->pathString, '/'), |
||
| 112 | ) |
||
| 113 | ) |
||
| 114 | ); |
||
| 115 | $generator->endAttribute('href'); |
||
| 116 | $generator->endObjectElement('Children'); |
||
| 117 | |||
| 118 | $generator->startObjectElement('Content'); |
||
| 119 | $generator->startAttribute( |
||
| 120 | 'href', |
||
| 121 | $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $location->contentId)) |
||
| 122 | ); |
||
| 123 | $generator->endAttribute('href'); |
||
| 124 | $generator->endObjectElement('Content'); |
||
| 125 | |||
| 126 | $generator->startValueElement('sortField', $this->serializeSortField($location->sortField)); |
||
| 127 | $generator->endValueElement('sortField'); |
||
| 128 | |||
| 129 | $generator->startValueElement('sortOrder', $this->serializeSortOrder($location->sortOrder)); |
||
| 130 | $generator->endValueElement('sortOrder'); |
||
| 131 | |||
| 132 | $generator->startObjectElement('UrlAliases', 'UrlAliasRefList'); |
||
| 133 | $generator->startAttribute( |
||
| 134 | 'href', |
||
| 135 | $this->router->generate( |
||
| 136 | 'ezpublish_rest_listLocationURLAliases', |
||
| 137 | array('locationPath' => trim($location->pathString, '/')) |
||
| 138 | ) |
||
| 139 | ); |
||
| 140 | $generator->endAttribute('href'); |
||
| 141 | $generator->endObjectElement('UrlAliases'); |
||
| 142 | |||
| 143 | $generator->startObjectElement('ContentInfo', 'ContentInfo'); |
||
| 144 | $generator->startAttribute( |
||
| 145 | 'href', |
||
| 146 | $this->router->generate( |
||
| 147 | 'ezpublish_rest_loadContent', |
||
| 148 | array('contentId' => $location->contentId) |
||
| 149 | ) |
||
| 150 | ); |
||
| 151 | $generator->endAttribute('href'); |
||
| 152 | $visitor->visitValueObject(new RestContentValue($location->contentInfo)); |
||
| 153 | $generator->endObjectElement('ContentInfo'); |
||
| 154 | } |
||
| 155 | } |
||
| 156 |