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 |
||
31 | class RespondService |
||
32 | { |
||
33 | /** @var SamlAuthenticationLogger */ |
||
34 | private $samlLogger; |
||
35 | |||
36 | /** @var LoaResolutionService */ |
||
37 | private $loaResolutionService; |
||
38 | |||
39 | /** @var LoaAliasLookupService */ |
||
40 | private $loaAliasLookupService; |
||
41 | |||
42 | /** @var ResponseFactory */ |
||
43 | private $responseFactory; |
||
44 | |||
45 | /** @var SecondFactorService */ |
||
46 | private $secondFactorService; |
||
47 | |||
48 | /** @var SecondFactorTypeService */ |
||
49 | private $secondFactorTypeService; |
||
50 | |||
51 | /** |
||
52 | * SecondFactorRespondService constructor. |
||
53 | * @param SamlAuthenticationLogger $samlLogger |
||
54 | * @param LoaResolutionService $loaResolutionService |
||
55 | * @param LoaAliasLookupService $loaAliasLookupService |
||
56 | * @param ResponseFactory $responseFactory |
||
57 | * @param SecondFactorService $secondFactorService |
||
58 | * @param SecondFactorTypeService $secondFactorTypeService |
||
59 | */ |
||
60 | View Code Duplication | public function __construct( |
|
75 | |||
76 | |||
77 | /** |
||
78 | * Send a SAML response back to the service provider. |
||
79 | * |
||
80 | * Second factor verification is finished. This method builds a AuthnResponse |
||
81 | * to send back to the service provider in response to the AuthnRequest received in |
||
82 | * the SecondFactorLoginService. |
||
83 | * |
||
84 | * @param ResponseContext $responseContext |
||
85 | * @return Response |
||
86 | */ |
||
87 | public function respond(ResponseContext $responseContext) |
||
127 | |||
128 | /** |
||
129 | * Reset the state of the response |
||
130 | * |
||
131 | * @param ResponseContext $responseContext |
||
132 | */ |
||
133 | public function resetRespondState(ResponseContext $responseContext) |
||
137 | } |
||
138 |
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.