Conditions | 1 |
Paths | 1 |
Total Lines | 61 |
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 testParentUserGroupLimitationAllow() |
||
30 | { |
||
31 | $repository = $this->getRepository(); |
||
32 | $userService = $repository->getUserService(); |
||
33 | $permissionResolver = $repository->getPermissionResolver(); |
||
34 | |||
35 | $parentUserGroupId = $this->generateId('location', 4); |
||
36 | /* BEGIN: Use Case */ |
||
37 | $user = $this->createUserVersion1(); |
||
38 | $currentUser = $userService->loadUser( |
||
39 | $permissionResolver->getCurrentUserReference()->getUserId() |
||
40 | ); |
||
41 | |||
42 | $userGroupCreate = $userService->newUserGroupCreateStruct('eng-GB'); |
||
43 | $userGroupCreate->setField('name', 'Shared wiki'); |
||
44 | |||
45 | $userGroup = $userService->createUserGroup( |
||
46 | $userGroupCreate, |
||
47 | $userService->loadUserGroup( |
||
48 | $parentUserGroupId |
||
49 | ) |
||
50 | ); |
||
51 | |||
52 | // Assign system user and example user to same group |
||
53 | $userService->assignUserToUserGroup($user, $userGroup); |
||
54 | $userService->assignUserToUserGroup($currentUser, $userGroup); |
||
55 | |||
56 | $roleService = $repository->getRoleService(); |
||
57 | |||
58 | $policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
||
59 | $policyCreate->addLimitation( |
||
60 | new ParentUserGroupLimitation( |
||
61 | [ |
||
62 | 'limitationValues' => [true], |
||
63 | ] |
||
64 | ) |
||
65 | ); |
||
66 | $role = $roleService->loadRoleByIdentifier('Editor'); |
||
67 | $roleDraft = $roleService->createRoleDraft($role); |
||
68 | $roleService->addPolicyByRoleDraft( |
||
69 | $roleDraft, |
||
70 | $policyCreate |
||
71 | ); |
||
72 | $roleService->addPolicyByRoleDraft( |
||
73 | $roleDraft, |
||
74 | $roleService->newPolicyCreateStruct('content', 'read') |
||
75 | ); |
||
76 | $roleService->publishRoleDraft($roleDraft); |
||
77 | |||
78 | $roleService->assignRoleToUserGroup($role, $userGroup); |
||
79 | |||
80 | $permissionResolver->setCurrentUserReference($user); |
||
81 | |||
82 | $draft = $this->createWikiPageDraft(); |
||
83 | /* END: Use Case */ |
||
84 | |||
85 | $this->assertEquals( |
||
86 | 'An awesome wiki page', |
||
87 | $draft->getFieldValue('title')->text |
||
88 | ); |
||
89 | } |
||
90 | |||
152 |