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