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 |
||
29 | class RespondService |
||
30 | { |
||
31 | /** @var SamlAuthenticationLogger */ |
||
32 | private $samlLogger; |
||
33 | |||
34 | /** @var LoaResolutionService */ |
||
35 | private $loaResolutionService; |
||
36 | |||
37 | /** @var ProxyResponseService */ |
||
38 | private $responseProxy; |
||
39 | |||
40 | /** @var SecondFactorService */ |
||
41 | private $secondFactorService; |
||
42 | |||
43 | /** @var SecondFactorTypeService */ |
||
44 | private $secondFactorTypeService; |
||
45 | |||
46 | /** |
||
47 | * GatewayServiceProviderService constructor. |
||
48 | * @param SamlAuthenticationLogger $samlLogger |
||
49 | * @param LoaResolutionService $loaResolutionService |
||
50 | * @param ProxyResponseService $responseProxy |
||
51 | * @param SecondFactorService $secondFactorService |
||
52 | * @param SecondFactorTypeService $secondFactorTypeService |
||
53 | */ |
||
54 | View Code Duplication | public function __construct( |
|
67 | |||
68 | /** |
||
69 | * Send a SAML response back to the service provider. |
||
70 | * |
||
71 | * Second factor verification handled by the LoginService is |
||
72 | * finished. This method sends a AuthnResponse back to the service |
||
73 | * provider in response to the AuthnRequest received in the LoginService. |
||
74 | * @param ResponseContext $responseContext |
||
75 | * @return SAMLResponse |
||
76 | */ |
||
77 | public function respond(ResponseContext $responseContext) |
||
110 | |||
111 | /** |
||
112 | * Reset the state of the response |
||
113 | * |
||
114 | * @param ResponseContext $responseContext |
||
115 | */ |
||
116 | public function resetRespondState(ResponseContext $responseContext) |
||
120 | } |
||
121 |
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.