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 |
||
20 | class Response extends StatusResponse |
||
21 | { |
||
22 | /** @var Assertion[] */ |
||
23 | protected $assertions = array(); |
||
24 | |||
25 | /** @var EncryptedElement[] */ |
||
26 | protected $encryptedAssertions = array(); |
||
27 | |||
28 | /** |
||
29 | * @return Assertion[] |
||
30 | */ |
||
31 | 21 | public function getAllAssertions() |
|
35 | |||
36 | /** |
||
37 | * @return Assertion|null |
||
38 | */ |
||
39 | 6 | public function getFirstAssertion() |
|
47 | |||
48 | /** |
||
49 | * @return EncryptedElement[] |
||
50 | */ |
||
51 | 12 | public function getAllEncryptedAssertions() |
|
55 | |||
56 | /** |
||
57 | * @return EncryptedElement|null |
||
58 | */ |
||
59 | 1 | public function getFirstEncryptedAssertion() |
|
67 | |||
68 | /** |
||
69 | * Returns assertions with <AuthnStatement> and <Subject> with at least one <SubjectConfirmation> |
||
70 | * element containing a Method of urn:oasis:names:tc:SAML:2.0:cm:bearer. |
||
71 | * |
||
72 | * @return \LightSaml\Model\Assertion\Assertion[] |
||
73 | */ |
||
74 | 3 | public function getBearerAssertions() |
|
87 | |||
88 | /** |
||
89 | * @param Assertion $assertion |
||
90 | * |
||
91 | * @return Response |
||
92 | */ |
||
93 | 15 | public function addAssertion(Assertion $assertion) |
|
99 | |||
100 | /** |
||
101 | * @param Assertion $removedAssertion |
||
102 | * |
||
103 | * @return Response |
||
104 | */ |
||
105 | public function removeAssertion(Assertion $removedAssertion) |
||
123 | |||
124 | /** |
||
125 | * @param EncryptedElement $encryptedAssertion |
||
126 | * |
||
127 | * @return Response |
||
128 | */ |
||
129 | 5 | public function addEncryptedAssertion(EncryptedElement $encryptedAssertion) |
|
135 | |||
136 | /** |
||
137 | * @param \DOMNode $parent |
||
138 | * @param SerializationContext $context |
||
139 | */ |
||
140 | 7 | public function serialize(\DOMNode $parent, SerializationContext $context) |
|
152 | |||
153 | /** |
||
154 | * @param \DOMNode $node |
||
155 | * @param DeserializationContext $context |
||
156 | */ |
||
157 | 7 | View Code Duplication | public function deserialize(\DOMNode $node, DeserializationContext $context) |
183 | } |
||
184 |
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.