| Conditions | 1 |
| Paths | 1 |
| Total Lines | 88 |
| Code Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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('TrashItem'); |
||
| 33 | $visitor->setHeader('Content-Type', $generator->getMediaType('TrashItem')); |
||
| 34 | |||
| 35 | $trashItem = $data->trashItem; |
||
| 36 | $contentInfo = $trashItem->getContentInfo(); |
||
| 37 | |||
| 38 | $generator->startAttribute( |
||
| 39 | 'href', |
||
| 40 | $this->router->generate('ezpublish_rest_loadTrashItem', array('trashItemId' => $trashItem->id)) |
||
|
|
|||
| 41 | ); |
||
| 42 | $generator->endAttribute('href'); |
||
| 43 | |||
| 44 | $generator->startValueElement('id', $trashItem->id); |
||
| 45 | $generator->endValueElement('id'); |
||
| 46 | |||
| 47 | $generator->startValueElement('priority', $trashItem->priority); |
||
| 48 | $generator->endValueElement('priority'); |
||
| 49 | |||
| 50 | $generator->startValueElement( |
||
| 51 | 'hidden', |
||
| 52 | $this->serializeBool($generator, $trashItem->hidden) |
||
| 53 | ); |
||
| 54 | $generator->endValueElement('hidden'); |
||
| 55 | |||
| 56 | $generator->startValueElement( |
||
| 57 | 'invisible', |
||
| 58 | $this->serializeBool($generator, $trashItem->invisible) |
||
| 59 | ); |
||
| 60 | $generator->endValueElement('invisible'); |
||
| 61 | |||
| 62 | $pathStringParts = explode('/', trim($trashItem->pathString, '/')); |
||
| 63 | $pathStringParts = array_slice($pathStringParts, 0, count($pathStringParts) - 1); |
||
| 64 | |||
| 65 | $generator->startObjectElement('ParentLocation', 'Location'); |
||
| 66 | $generator->startAttribute( |
||
| 67 | 'href', |
||
| 68 | $this->router->generate( |
||
| 69 | 'ezpublish_rest_loadLocation', |
||
| 70 | array( |
||
| 71 | 'locationPath' => implode('/', $pathStringParts), |
||
| 72 | ) |
||
| 73 | ) |
||
| 74 | ); |
||
| 75 | $generator->endAttribute('href'); |
||
| 76 | $generator->endObjectElement('ParentLocation'); |
||
| 77 | |||
| 78 | $generator->startValueElement('pathString', $trashItem->pathString); |
||
| 79 | $generator->endValueElement('pathString'); |
||
| 80 | |||
| 81 | $generator->startValueElement('depth', $trashItem->depth); |
||
| 82 | $generator->endValueElement('depth'); |
||
| 83 | |||
| 84 | $generator->startValueElement('childCount', $data->childCount); |
||
| 85 | $generator->endValueElement('childCount'); |
||
| 86 | |||
| 87 | $generator->startValueElement('remoteId', $trashItem->remoteId); |
||
| 88 | $generator->endValueElement('remoteId'); |
||
| 89 | |||
| 90 | $generator->startObjectElement('Content'); |
||
| 91 | $generator->startAttribute( |
||
| 92 | 'href', |
||
| 93 | $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $contentInfo->id)) |
||
| 94 | ); |
||
| 95 | $generator->endAttribute('href'); |
||
| 96 | $generator->endObjectElement('Content'); |
||
| 97 | |||
| 98 | $generator->startValueElement('sortField', $this->serializeSortField($trashItem->sortField)); |
||
| 99 | $generator->endValueElement('sortField'); |
||
| 100 | |||
| 101 | $generator->startValueElement('sortOrder', $this->serializeSortOrder($trashItem->sortOrder)); |
||
| 102 | $generator->endValueElement('sortOrder'); |
||
| 103 | |||
| 104 | $generator->startObjectElement('ContentInfo', 'ContentInfo'); |
||
| 105 | $generator->startAttribute( |
||
| 106 | 'href', |
||
| 107 | $this->router->generate( |
||
| 108 | 'ezpublish_rest_loadContent', |
||
| 109 | array('contentId' => $contentInfo->id) |
||
| 110 | ) |
||
| 111 | ); |
||
| 112 | $generator->endAttribute('href'); |
||
| 113 | $visitor->visitValueObject(new RestContentValue($contentInfo)); |
||
| 114 | $generator->endObjectElement('ContentInfo'); |
||
| 115 | |||
| 116 | $generator->endObjectElement('TrashItem'); |
||
| 117 | } |
||
| 118 | } |
||
| 119 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.