| Conditions | 4 |
| Paths | 3 |
| Total Lines | 54 |
| Code Lines | 33 |
| 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 |
||
| 29 | public function visit(Visitor $visitor, Generator $generator, $data) |
||
| 30 | { |
||
| 31 | $generator->startObjectElement('UserGroupRefList'); |
||
| 32 | $visitor->setHeader('Content-Type', $generator->getMediaType('UserGroupRefList')); |
||
| 33 | //@todo Needs refactoring, disabling certain headers should not be done this way |
||
| 34 | $visitor->setHeader('Accept-Patch', false); |
||
|
|
|||
| 35 | |||
| 36 | $generator->startAttribute('href', $data->path); |
||
| 37 | $generator->endAttribute('href'); |
||
| 38 | |||
| 39 | $groupCount = count($data->userGroups); |
||
| 40 | |||
| 41 | $generator->startList('UserGroup'); |
||
| 42 | foreach ($data->userGroups as $userGroup) { |
||
| 43 | $generator->startObjectElement('UserGroup'); |
||
| 44 | |||
| 45 | $generator->startAttribute( |
||
| 46 | 'href', |
||
| 47 | $this->router->generate( |
||
| 48 | 'ezpublish_rest_loadUserGroup', |
||
| 49 | array( |
||
| 50 | 'groupPath' => trim($userGroup->mainLocation->pathString, '/'), |
||
| 51 | ) |
||
| 52 | ) |
||
| 53 | ); |
||
| 54 | $generator->endAttribute('href'); |
||
| 55 | |||
| 56 | if ($data->userId !== null && $groupCount > 1) { |
||
| 57 | $generator->startHashElement('unassign'); |
||
| 58 | |||
| 59 | $generator->startAttribute( |
||
| 60 | 'href', |
||
| 61 | $this->router->generate( |
||
| 62 | 'ezpublish_rest_unassignUserFromUserGroup', |
||
| 63 | array( |
||
| 64 | 'userId' => $data->userId, |
||
| 65 | 'groupPath' => $userGroup->mainLocation->path[count($userGroup->mainLocation->path) - 1], |
||
| 66 | ) |
||
| 67 | ) |
||
| 68 | ); |
||
| 69 | $generator->endAttribute('href'); |
||
| 70 | |||
| 71 | $generator->startAttribute('method', 'DELETE'); |
||
| 72 | $generator->endAttribute('method'); |
||
| 73 | |||
| 74 | $generator->endHashElement('unassign'); |
||
| 75 | } |
||
| 76 | |||
| 77 | $generator->endObjectElement('UserGroup'); |
||
| 78 | } |
||
| 79 | $generator->endList('UserGroup'); |
||
| 80 | |||
| 81 | $generator->endObjectElement('UserGroupRefList'); |
||
| 82 | } |
||
| 83 | } |
||
| 84 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: