| Conditions | 1 |
| Paths | 1 |
| Total Lines | 85 |
| Code Lines | 82 |
| 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 |
||
| 98 | private function getAllSignals() |
||
| 99 | { |
||
| 100 | return array( |
||
| 101 | 'eZ\Publish\Core\SignalSlot\Signal\URLAliasService\CreateUrlAliasSignal', |
||
| 102 | 'eZ\Publish\Core\SignalSlot\Signal\URLAliasService\RemoveAliasesSignal', |
||
| 103 | 'eZ\Publish\Core\SignalSlot\Signal\URLAliasService\CreateGlobalUrlAliasSignal', |
||
| 104 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\CreateContentTypeSignal', |
||
| 105 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\AddFieldDefinitionSignal', |
||
| 106 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\CopyContentTypeSignal', |
||
| 107 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\DeleteContentTypeSignal', |
||
| 108 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\UpdateContentTypeGroupSignal', |
||
| 109 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\DeleteContentTypeGroupSignal', |
||
| 110 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\UnassignContentTypeGroupSignal', |
||
| 111 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\PublishContentTypeDraftSignal', |
||
| 112 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\AssignContentTypeGroupSignal', |
||
| 113 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\UpdateFieldDefinitionSignal', |
||
| 114 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\UpdateContentTypeDraftSignal', |
||
| 115 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\RemoveFieldDefinitionSignal', |
||
| 116 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\CreateContentTypeDraftSignal', |
||
| 117 | 'eZ\Publish\Core\SignalSlot\Signal\ContentTypeService\CreateContentTypeGroupSignal', |
||
| 118 | 'eZ\Publish\Core\SignalSlot\Signal\LanguageService\EnableLanguageSignal', |
||
| 119 | 'eZ\Publish\Core\SignalSlot\Signal\LanguageService\UpdateLanguageNameSignal', |
||
| 120 | 'eZ\Publish\Core\SignalSlot\Signal\LanguageService\CreateLanguageSignal', |
||
| 121 | 'eZ\Publish\Core\SignalSlot\Signal\LanguageService\DisableLanguageSignal', |
||
| 122 | 'eZ\Publish\Core\SignalSlot\Signal\LanguageService\DeleteLanguageSignal', |
||
| 123 | 'eZ\Publish\Core\SignalSlot\Signal\UserService\MoveUserGroupSignal', |
||
| 124 | 'eZ\Publish\Core\SignalSlot\Signal\UserService\DeleteUserGroupSignal', |
||
| 125 | 'eZ\Publish\Core\SignalSlot\Signal\UserService\CreateUserGroupSignal', |
||
| 126 | 'eZ\Publish\Core\SignalSlot\Signal\UserService\UpdateUserGroupSignal', |
||
| 127 | 'eZ\Publish\Core\SignalSlot\Signal\UserService\UnAssignUserFromUserGroupSignal', |
||
| 128 | 'eZ\Publish\Core\SignalSlot\Signal\UserService\AssignUserToUserGroupSignal', |
||
| 129 | 'eZ\Publish\Core\SignalSlot\Signal\UserService\DeleteUserSignal', |
||
| 130 | 'eZ\Publish\Core\SignalSlot\Signal\UserService\CreateUserSignal', |
||
| 131 | 'eZ\Publish\Core\SignalSlot\Signal\UserService\UpdateUserSignal', |
||
| 132 | 'eZ\Publish\Core\SignalSlot\Signal\SectionService\DeleteSectionSignal', |
||
| 133 | 'eZ\Publish\Core\SignalSlot\Signal\SectionService\CreateSectionSignal', |
||
| 134 | 'eZ\Publish\Core\SignalSlot\Signal\SectionService\UpdateSectionSignal', |
||
| 135 | 'eZ\Publish\Core\SignalSlot\Signal\SectionService\AssignSectionSignal', |
||
| 136 | 'eZ\Publish\Core\SignalSlot\Signal\RoleService\AssignRoleToUserGroupSignal', |
||
| 137 | 'eZ\Publish\Core\SignalSlot\Signal\RoleService\UpdatePolicySignal', |
||
| 138 | 'eZ\Publish\Core\SignalSlot\Signal\RoleService\CreateRoleSignal', |
||
| 139 | 'eZ\Publish\Core\SignalSlot\Signal\RoleService\RemovePolicySignal', |
||
| 140 | 'eZ\Publish\Core\SignalSlot\Signal\RoleService\UnassignRoleFromUserSignal', |
||
| 141 | 'eZ\Publish\Core\SignalSlot\Signal\RoleService\AddPolicySignal', |
||
| 142 | 'eZ\Publish\Core\SignalSlot\Signal\RoleService\UnassignRoleFromUserGroupSignal', |
||
| 143 | 'eZ\Publish\Core\SignalSlot\Signal\RoleService\UpdateRoleSignal', |
||
| 144 | 'eZ\Publish\Core\SignalSlot\Signal\RoleService\AssignRoleToUserSignal', |
||
| 145 | 'eZ\Publish\Core\SignalSlot\Signal\RoleService\DeleteRoleSignal', |
||
| 146 | 'eZ\Publish\Core\SignalSlot\Signal\TrashService\TrashSignal', |
||
| 147 | 'eZ\Publish\Core\SignalSlot\Signal\TrashService\EmptyTrashSignal', |
||
| 148 | 'eZ\Publish\Core\SignalSlot\Signal\TrashService\RecoverSignal', |
||
| 149 | 'eZ\Publish\Core\SignalSlot\Signal\TrashService\DeleteTrashItemSignal', |
||
| 150 | 'eZ\Publish\Core\SignalSlot\Signal\ObjectStateService\DeleteObjectStateSignal', |
||
| 151 | 'eZ\Publish\Core\SignalSlot\Signal\ObjectStateService\CreateObjectStateSignal', |
||
| 152 | 'eZ\Publish\Core\SignalSlot\Signal\ObjectStateService\DeleteObjectStateGroupSignal', |
||
| 153 | 'eZ\Publish\Core\SignalSlot\Signal\ObjectStateService\CreateObjectStateGroupSignal', |
||
| 154 | 'eZ\Publish\Core\SignalSlot\Signal\ObjectStateService\UpdateObjectStateSignal', |
||
| 155 | 'eZ\Publish\Core\SignalSlot\Signal\ObjectStateService\UpdateObjectStateGroupSignal', |
||
| 156 | 'eZ\Publish\Core\SignalSlot\Signal\ObjectStateService\SetContentStateSignal', |
||
| 157 | 'eZ\Publish\Core\SignalSlot\Signal\ObjectStateService\SetPriorityOfObjectStateSignal', |
||
| 158 | 'eZ\Publish\Core\SignalSlot\Signal\URLWildcardService\TranslateSignal', |
||
| 159 | 'eZ\Publish\Core\SignalSlot\Signal\URLWildcardService\RemoveSignal', |
||
| 160 | 'eZ\Publish\Core\SignalSlot\Signal\URLWildcardService\CreateSignal', |
||
| 161 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\UpdateContentSignal', |
||
| 162 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\CreateContentDraftSignal', |
||
| 163 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\AddRelationSignal', |
||
| 164 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\CreateContentSignal', |
||
| 165 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteContentSignal', |
||
| 166 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\AddTranslationInfoSignal', |
||
| 167 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\CopyContentSignal', |
||
| 168 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\UpdateContentMetadataSignal', |
||
| 169 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\TranslateVersionSignal', |
||
| 170 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\PublishVersionSignal', |
||
| 171 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteRelationSignal', |
||
| 172 | 'eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteVersionSignal', |
||
| 173 | 'eZ\Publish\Core\SignalSlot\Signal\LocationService\UpdateLocationSignal', |
||
| 174 | 'eZ\Publish\Core\SignalSlot\Signal\LocationService\HideLocationSignal', |
||
| 175 | 'eZ\Publish\Core\SignalSlot\Signal\LocationService\SwapLocationSignal', |
||
| 176 | 'eZ\Publish\Core\SignalSlot\Signal\LocationService\MoveSubtreeSignal', |
||
| 177 | 'eZ\Publish\Core\SignalSlot\Signal\LocationService\UnhideLocationSignal', |
||
| 178 | 'eZ\Publish\Core\SignalSlot\Signal\LocationService\CreateLocationSignal', |
||
| 179 | 'eZ\Publish\Core\SignalSlot\Signal\LocationService\DeleteLocationSignal', |
||
| 180 | 'eZ\Publish\Core\SignalSlot\Signal\LocationService\CopySubtreeSignal', |
||
| 181 | ); |
||
| 182 | } |
||
| 183 | } |
||
| 184 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: