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 |
||
17 | class AuthMiddlewareTest extends BaseTestCase |
||
18 | { |
||
19 | /** @var AuthOptions $authOptions */ |
||
20 | protected $authOptions; |
||
21 | |||
22 | /** @var callable $callable */ |
||
23 | protected $callable; |
||
24 | |||
25 | /** @var ServerRequest $request */ |
||
26 | protected $request; |
||
27 | |||
28 | /** @var Response $response */ |
||
29 | protected $response; |
||
30 | |||
31 | /** |
||
32 | * @throws \Potievdev\SlimRbac\Exception\CyclicException |
||
33 | * @throws \Potievdev\SlimRbac\Exception\DatabaseException |
||
34 | * @throws \Potievdev\SlimRbac\Exception\NotUniqueException |
||
35 | * @throws \Doctrine\ORM\Query\QueryException |
||
36 | */ |
||
37 | public function setUp() |
||
75 | |||
76 | /** |
||
77 | * @throws \Doctrine\ORM\Query\QueryException |
||
78 | * @throws \Potievdev\SlimRbac\Exception\InvalidArgumentException |
||
79 | */ |
||
80 | View Code Duplication | public function testCheckAccessSuccessCase() |
|
87 | |||
88 | /** |
||
89 | * @throws \Doctrine\ORM\Query\QueryException |
||
90 | * @throws \Potievdev\SlimRbac\Exception\InvalidArgumentException |
||
91 | */ |
||
92 | View Code Duplication | public function testCheckAccessDeniedCase() |
|
99 | |||
100 | /** |
||
101 | * @throws \Doctrine\ORM\Query\QueryException |
||
102 | * @throws \Potievdev\SlimRbac\Exception\InvalidArgumentException |
||
103 | */ |
||
104 | View Code Duplication | public function testCheckReadingUserIdFromHeader() |
|
113 | |||
114 | /** |
||
115 | * @throws \Doctrine\ORM\Query\QueryException |
||
116 | * @throws \Potievdev\SlimRbac\Exception\InvalidArgumentException |
||
117 | */ |
||
118 | View Code Duplication | public function testCheckReadingUserIdFromCookie() |
|
127 | |||
128 | } |
||
129 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.