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 FunctionalTest extends WebTestCase |
||
18 | { |
||
19 | // @codingStandardsIgnoreStart |
||
20 | const PSK_TOKEN = AuthenticatorTest::TEST_TOKEN; |
||
21 | const HMAC_TOKEN = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleVR3byJ9.eyJwcm4iOiJqb2huIiwiaXNzIjoiaHR0cDovL2FwaS5zZXJ2ZXIyLmNvbS9vYXV0aDIvdG9rZW4ifQ.vdGhD5E4Ibj2Tndlh_0pPgJsOuRUpAn1QYu5miB6qwjrXhKCicuTKOuC9x2_2ErUOApv5KiblYds_gcWONdGKx1tQyQa1dsuhrkiVn_VJAsaaix8nJiHAuNv-ukm8mnSWJoVuOcTQIQG8IaupviyphEAEdjrm9QQhvzERgdFUT4bdCdfywrC37oYEAH5bHpiiUK2UzyNuUIHwOP_gWODodbEWRJOxtefwJ_vdpqHvSZzyW7Vei4mCtr2vE1k2qBvG_Qjw2ebLfEdX58k6-eYa7phle9hYjA_q-I8Y-S1ulBiVf_tpvayk8-4lWup9Wbg_BT2vDJOidQgM4l9jV9QHg'; |
||
22 | const DYN_HMAC_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleVRocmVlIn0.eyJwcm4iOiJqb2UiLCJpc3MiOiJodHRwOi8vYXBpLnNlcnZlcjIuY29tL29hdXRoMi90b2tlbiJ9.fv9yrTk3AnPTle_ikBY2EjIFhb1xaxKO4-Vop2AxnME'; |
||
23 | // @codingStandardsIgnoreEnd |
||
24 | |||
25 | /** |
||
26 | * @test |
||
27 | */ |
||
28 | public function canGetUnsecuredContentWithoutToken() |
||
34 | |||
35 | /** |
||
36 | * @test |
||
37 | * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException |
||
38 | */ |
||
39 | public function cannotGetSecuredContentWithoutToken() |
||
44 | |||
45 | /** |
||
46 | * @test |
||
47 | * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException |
||
48 | */ |
||
49 | public function cannotGetSecuredContentWitInvalidToken() |
||
55 | |||
56 | /** |
||
57 | * @test |
||
58 | */ |
||
59 | View Code Duplication | public function canGetSecuredContentWitValidPskToken() |
|
66 | |||
67 | /** |
||
68 | * @test |
||
69 | */ |
||
70 | View Code Duplication | public function canGetSecuredContentWitValidHmacToken() |
|
77 | |||
78 | /** |
||
79 | * @test |
||
80 | */ |
||
81 | View Code Duplication | public function canGetSecuredContentWithSecretLoader() |
|
88 | } |
||
89 |
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.