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 |
||
| 13 | class EncryptedAssertion |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * The current encrypted assertion. |
||
| 17 | * |
||
| 18 | * @var \DOMElement |
||
| 19 | */ |
||
| 20 | private $encryptedData; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Constructor for SAML 2 encrypted assertions. |
||
| 24 | * |
||
| 25 | * @param \DOMElement|null $xml The encrypted assertion XML element. |
||
| 26 | * @throws \Exception |
||
| 27 | */ |
||
| 28 | public function __construct(\DOMElement $xml = null) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Set the assertion. |
||
| 45 | * |
||
| 46 | * @param \SAML2\Assertion $assertion The assertion. |
||
| 47 | * @param XMLSecurityKey $key The key we should use to encrypt the assertion. |
||
| 48 | * @throws \Exception |
||
| 49 | */ |
||
| 50 | public function setAssertion(Assertion $assertion, XMLSecurityKey $key) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Retrieve the assertion. |
||
| 86 | * |
||
| 87 | * @param XMLSecurityKey $inputKey The key we should use to decrypt the assertion. |
||
| 88 | * @param array $blacklist Blacklisted decryption algorithms. |
||
| 89 | * @return \SAML2\Assertion The decrypted assertion. |
||
| 90 | */ |
||
| 91 | public function getAssertion(XMLSecurityKey $inputKey, array $blacklist = array()) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Convert this encrypted assertion to an XML element. |
||
| 102 | * |
||
| 103 | * @param \DOMNode|null $parentElement The DOM node the assertion should be created in. |
||
| 104 | * @return \DOMElement This encrypted assertion. |
||
| 105 | */ |
||
| 106 | public function toXML(\DOMNode $parentElement = null) |
||
| 122 | } |
||
| 123 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: