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 |
||
36 | class ProxyResponseFactory |
||
37 | { |
||
38 | /** |
||
39 | * @var \Surfnet\SamlBundle\Entity\IdentityProvider |
||
40 | */ |
||
41 | private $hostedIdentityProvider; |
||
42 | |||
43 | /** |
||
44 | * @var \Surfnet\StepupGateway\SamlStepupProviderBundle\Saml\StateHandler |
||
45 | */ |
||
46 | private $stateHandler; |
||
47 | |||
48 | /** |
||
49 | * @var \Surfnet\StepupGateway\GatewayBundle\Saml\AssertionSigningService |
||
50 | */ |
||
51 | private $assertionSigningService; |
||
52 | |||
53 | /** |
||
54 | * @var \DateTime |
||
55 | */ |
||
56 | private $currentTime; |
||
57 | |||
58 | View Code Duplication | public function __construct( |
|
|
|||
59 | IdentityProvider $hostedIdentityProvider, |
||
60 | StateHandler $stateHandler, |
||
61 | AssertionSigningService $assertionSigningService |
||
62 | ) { |
||
63 | $this->hostedIdentityProvider = $hostedIdentityProvider; |
||
64 | $this->stateHandler = $stateHandler; |
||
65 | $this->assertionSigningService = $assertionSigningService; |
||
66 | |||
67 | $this->currentTime = new DateTime('now', new DateTimeZone('UTC')); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param SAML2_Assertion $assertion |
||
72 | * @param ServiceProvider $targetServiceProvider |
||
73 | * @return SAML2_Response |
||
74 | */ |
||
75 | public function createProxyResponse(SAML2_Assertion $assertion, ServiceProvider $targetServiceProvider) |
||
94 | |||
95 | /** |
||
96 | * @param SAML2_Assertion $newAssertion |
||
97 | * @param ServiceProvider $targetServiceProvider |
||
98 | */ |
||
99 | View Code Duplication | private function addSubjectConfirmationFor(SAML2_Assertion $newAssertion, ServiceProvider $targetServiceProvider) |
|
113 | |||
114 | /** |
||
115 | * @param SAML2_Assertion $newAssertion |
||
116 | * @param SAML2_Assertion $assertion |
||
117 | */ |
||
118 | private function addAuthenticationStatementTo(SAML2_Assertion $newAssertion, SAML2_Assertion $assertion) |
||
124 | |||
125 | /** |
||
126 | * @param SAML2_Assertion $newAssertion |
||
127 | * @param ServiceProvider $targetServiceProvider |
||
128 | * @return SAML2_Response |
||
129 | */ |
||
130 | View Code Duplication | private function createNewAuthnResponse(SAML2_Assertion $newAssertion, ServiceProvider $targetServiceProvider) |
|
141 | |||
142 | /** |
||
143 | * @param string $interval a DateInterval compatible interval to skew the time with |
||
144 | * @return int |
||
145 | */ |
||
146 | View Code Duplication | private function getTimestamp($interval = null) |
|
156 | } |
||
157 |
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.