Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 25 | class ParentDepthLimitationTest extends BaseLimitationTest |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * Tests a combination of ParentDepthLimitation and ContentTypeLimitation. |
||
| 29 | * |
||
| 30 | * @see \eZ\Publish\API\Repository\Values\User\Limitation\ContentTypeLimitation |
||
| 31 | * @see \eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation |
||
| 32 | * |
||
| 33 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 34 | */ |
||
| 35 | View Code Duplication | public function testParentDepthLimitationForbid() |
|
| 36 | { |
||
| 37 | $repository = $this->getRepository(); |
||
| 38 | |||
| 39 | $contentTypeId = $this->generateId('contentType', 22); |
||
| 40 | /* BEGIN: Use Case */ |
||
| 41 | $user = $this->createUserVersion1(); |
||
| 42 | |||
| 43 | $roleService = $repository->getRoleService(); |
||
| 44 | |||
| 45 | $role = $roleService->loadRoleByIdentifier('Editor'); |
||
| 46 | |||
| 47 | $policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
||
| 48 | $policyCreate->addLimitation( |
||
| 49 | new ParentDepthLimitation( |
||
| 50 | array('limitationValues' => array(3)) |
||
| 51 | ) |
||
| 52 | ); |
||
| 53 | $policyCreate->addLimitation( |
||
| 54 | new ContentTypeLimitation( |
||
| 55 | array('limitationValues' => array($contentTypeId)) |
||
| 56 | ) |
||
| 57 | ); |
||
| 58 | |||
| 59 | $role = $roleService->addPolicy($role, $policyCreate); |
||
|
|
|||
| 60 | |||
| 61 | $roleService->assignRoleToUser($role, $user); |
||
| 62 | |||
| 63 | $repository->setCurrentUser($user); |
||
| 64 | |||
| 65 | $draft = $this->createWikiPageDraft(); |
||
| 66 | /* END: Use Case */ |
||
| 67 | |||
| 68 | $this->assertEquals( |
||
| 69 | 'An awesome wiki page', |
||
| 70 | $draft->getFieldValue('title')->text |
||
| 71 | ); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Tests a combination of ParentDepthLimitation and ContentTypeLimitation. |
||
| 76 | * |
||
| 77 | * @see \eZ\Publish\API\Repository\Values\User\Limitation\ContentTypeLimitation |
||
| 78 | * @see \eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation |
||
| 79 | */ |
||
| 80 | public function testParentDepthLimitationAllow() |
||
| 81 | { |
||
| 82 | $repository = $this->getRepository(); |
||
| 83 | |||
| 84 | $contentTypeId = $this->generateId('contentType', 22); |
||
| 85 | /* BEGIN: Use Case */ |
||
| 86 | $user = $this->createUserVersion1(); |
||
| 87 | |||
| 88 | $roleService = $repository->getRoleService(); |
||
| 89 | |||
| 90 | $role = $roleService->loadRoleByIdentifier('Editor'); |
||
| 91 | |||
| 92 | $policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
||
| 93 | $policyCreate->addLimitation( |
||
| 94 | new ParentDepthLimitation( |
||
| 95 | array('limitationValues' => array(1, 2, 3, 4)) |
||
| 96 | ) |
||
| 97 | ); |
||
| 98 | $policyCreate->addLimitation( |
||
| 99 | new ContentTypeLimitation( |
||
| 100 | array('limitationValues' => array($contentTypeId)) |
||
| 101 | ) |
||
| 102 | ); |
||
| 103 | |||
| 104 | $role = $roleService->addPolicy($role, $policyCreate); |
||
| 105 | |||
| 106 | $roleService->assignRoleToUser($role, $user); |
||
| 107 | |||
| 108 | $repository->setCurrentUser($user); |
||
| 109 | |||
| 110 | $this->createWikiPageDraft(); |
||
| 111 | /* END: Use Case */ |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Tests a combination of ParentDepthLimitation and ContentTypeLimitation. |
||
| 116 | * |
||
| 117 | * @depends testParentDepthLimitationAllow |
||
| 118 | * |
||
| 119 | * @see \eZ\Publish\API\Repository\Values\User\Limitation\ContentTypeLimitation |
||
| 120 | * @see \eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation |
||
| 121 | */ |
||
| 122 | public function testParentDepthLimitationAllowPublish() |
||
| 159 | } |
||
| 160 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.