| Conditions | 1 |
| Paths | 1 |
| Total Lines | 78 |
| Code Lines | 53 |
| 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 |
||
| 59 | public function testSetIdentity() |
||
| 60 | { |
||
| 61 | $user = $this->createMock(APIUser::class); |
||
| 62 | $userContext = new UserContext(); |
||
| 63 | |||
| 64 | $this->repositoryMock |
||
| 65 | ->expects($this->once()) |
||
| 66 | ->method('getCurrentUser') |
||
| 67 | ->will($this->returnValue($user)); |
||
| 68 | |||
| 69 | $roleId1 = 123; |
||
| 70 | $roleId2 = 456; |
||
| 71 | $roleId3 = 789; |
||
| 72 | $limitationForRole2 = $this->generateLimitationMock( |
||
| 73 | array( |
||
| 74 | 'limitationValues' => array('/1/2', '/1/2/43'), |
||
| 75 | ) |
||
| 76 | ); |
||
| 77 | $limitationForRole3 = $this->generateLimitationMock( |
||
| 78 | array( |
||
| 79 | 'limitationValues' => array('foo', 'bar'), |
||
| 80 | ) |
||
| 81 | ); |
||
| 82 | $returnedRoleAssignments = array( |
||
| 83 | $this->generateRoleAssignmentMock( |
||
| 84 | array( |
||
| 85 | 'role' => $this->generateRoleMock( |
||
| 86 | array( |
||
| 87 | 'id' => $roleId1, |
||
| 88 | ) |
||
| 89 | ), |
||
| 90 | ) |
||
| 91 | ), |
||
| 92 | $this->generateRoleAssignmentMock( |
||
| 93 | array( |
||
| 94 | 'role' => $this->generateRoleMock( |
||
| 95 | array( |
||
| 96 | 'id' => $roleId2, |
||
| 97 | ) |
||
| 98 | ), |
||
| 99 | 'limitation' => $limitationForRole2, |
||
| 100 | ) |
||
| 101 | ), |
||
| 102 | $this->generateRoleAssignmentMock( |
||
| 103 | array( |
||
| 104 | 'role' => $this->generateRoleMock( |
||
| 105 | array( |
||
| 106 | 'id' => $roleId3, |
||
| 107 | ) |
||
| 108 | ), |
||
| 109 | 'limitation' => $limitationForRole3, |
||
| 110 | ) |
||
| 111 | ), |
||
| 112 | ); |
||
| 113 | |||
| 114 | $this->roleServiceMock |
||
| 115 | ->expects($this->once()) |
||
| 116 | ->method('getRoleAssignmentsForUser') |
||
| 117 | ->with($user, true) |
||
| 118 | ->will($this->returnValue($returnedRoleAssignments)); |
||
| 119 | |||
| 120 | $this->assertSame(array(), $userContext->getParameters()); |
||
| 121 | $contextProvider = new RoleContextProvider($this->repositoryMock); |
||
| 122 | $contextProvider->updateUserContext($userContext); |
||
| 123 | $userContextParams = $userContext->getParameters(); |
||
| 124 | $this->assertArrayHasKey('roleIdList', $userContextParams); |
||
| 125 | $this->assertSame(array($roleId1, $roleId2, $roleId3), $userContextParams['roleIdList']); |
||
| 126 | $this->assertArrayHasKey('roleLimitationList', $userContextParams); |
||
| 127 | $limitationIdentifierForRole2 = get_class($limitationForRole2); |
||
| 128 | $limitationIdentifierForRole3 = get_class($limitationForRole3); |
||
| 129 | $this->assertSame( |
||
| 130 | array( |
||
| 131 | "$roleId2-$limitationIdentifierForRole2" => array('/1/2', '/1/2/43'), |
||
| 132 | "$roleId3-$limitationIdentifierForRole3" => array('foo', 'bar'), |
||
| 133 | ), |
||
| 134 | $userContextParams['roleLimitationList'] |
||
| 135 | ); |
||
| 136 | } |
||
| 137 | |||
| 184 |