| Conditions | 1 |
| Paths | 1 |
| Total Lines | 87 |
| Code Lines | 59 |
| 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 | |||
| 37 | $generator->startAttribute( |
||
| 38 | 'href', |
||
| 39 | $this->router->generate('ezpublish_rest_loadTrashItem', array('trashItemId' => $trashItem->id)) |
||
|
|
|||
| 40 | ); |
||
| 41 | $generator->endAttribute('href'); |
||
| 42 | |||
| 43 | $generator->startValueElement('id', $trashItem->id); |
||
| 44 | $generator->endValueElement('id'); |
||
| 45 | |||
| 46 | $generator->startValueElement('priority', $trashItem->priority); |
||
| 47 | $generator->endValueElement('priority'); |
||
| 48 | |||
| 49 | $generator->startValueElement( |
||
| 50 | 'hidden', |
||
| 51 | $this->serializeBool($generator, $trashItem->hidden) |
||
| 52 | ); |
||
| 53 | $generator->endValueElement('hidden'); |
||
| 54 | |||
| 55 | $generator->startValueElement( |
||
| 56 | 'invisible', |
||
| 57 | $this->serializeBool($generator, $trashItem->invisible) |
||
| 58 | ); |
||
| 59 | $generator->endValueElement('invisible'); |
||
| 60 | |||
| 61 | $pathStringParts = explode('/', trim($trashItem->pathString, '/')); |
||
| 62 | $pathStringParts = array_slice($pathStringParts, 0, count($pathStringParts) - 1); |
||
| 63 | |||
| 64 | $generator->startObjectElement('ParentLocation', 'Location'); |
||
| 65 | $generator->startAttribute( |
||
| 66 | 'href', |
||
| 67 | $this->router->generate( |
||
| 68 | 'ezpublish_rest_loadLocation', |
||
| 69 | array( |
||
| 70 | 'locationPath' => implode('/', $pathStringParts), |
||
| 71 | ) |
||
| 72 | ) |
||
| 73 | ); |
||
| 74 | $generator->endAttribute('href'); |
||
| 75 | $generator->endObjectElement('ParentLocation'); |
||
| 76 | |||
| 77 | $generator->startValueElement('pathString', $trashItem->pathString); |
||
| 78 | $generator->endValueElement('pathString'); |
||
| 79 | |||
| 80 | $generator->startValueElement('depth', $trashItem->depth); |
||
| 81 | $generator->endValueElement('depth'); |
||
| 82 | |||
| 83 | $generator->startValueElement('childCount', $data->childCount); |
||
| 84 | $generator->endValueElement('childCount'); |
||
| 85 | |||
| 86 | $generator->startValueElement('remoteId', $trashItem->remoteId); |
||
| 87 | $generator->endValueElement('remoteId'); |
||
| 88 | |||
| 89 | $generator->startObjectElement('Content'); |
||
| 90 | $generator->startAttribute( |
||
| 91 | 'href', |
||
| 92 | $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $trashItem->contentId)) |
||
| 93 | ); |
||
| 94 | $generator->endAttribute('href'); |
||
| 95 | $generator->endObjectElement('Content'); |
||
| 96 | |||
| 97 | $generator->startValueElement('sortField', $this->serializeSortField($trashItem->sortField)); |
||
| 98 | $generator->endValueElement('sortField'); |
||
| 99 | |||
| 100 | $generator->startValueElement('sortOrder', $this->serializeSortOrder($trashItem->sortOrder)); |
||
| 101 | $generator->endValueElement('sortOrder'); |
||
| 102 | |||
| 103 | $generator->startObjectElement('ContentInfo', 'ContentInfo'); |
||
| 104 | $generator->startAttribute( |
||
| 105 | 'href', |
||
| 106 | $this->router->generate( |
||
| 107 | 'ezpublish_rest_loadContent', |
||
| 108 | array('contentId' => $trashItem->contentId) |
||
| 109 | ) |
||
| 110 | ); |
||
| 111 | $generator->endAttribute('href'); |
||
| 112 | $visitor->visitValueObject(new RestContentValue($trashItem->contentInfo)); |
||
| 113 | $generator->endObjectElement('ContentInfo'); |
||
| 114 | |||
| 115 | $generator->endObjectElement('TrashItem'); |
||
| 116 | } |
||
| 117 | } |
||
| 118 |
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.