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 |
||
| 23 | final class Encrypter implements EncrypterInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var null|\SpomkyLabs\JoseBundle\Model\JotManagerInterface |
||
| 27 | */ |
||
| 28 | private $jot_manager; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var \Jose\Encrypter |
||
| 32 | */ |
||
| 33 | private $encrypter; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Encrypter constructor. |
||
| 37 | * |
||
| 38 | * @param \Jose\Algorithm\JWAManagerInterface $jwa_manager |
||
| 39 | * @param \Jose\Payload\PayloadConverterManagerInterface $payload_converter_manager |
||
| 40 | * @param \Jose\Compression\CompressionManagerInterface $compression_manager |
||
| 41 | * @param \SpomkyLabs\JoseBundle\Model\JotManagerInterface|null $jot_manager |
||
| 42 | */ |
||
| 43 | public function __construct( |
||
| 52 | |||
| 53 | /** |
||
| 54 | * {@inheritdoc} |
||
| 55 | */ |
||
| 56 | public function encrypt($input, array $instructions, $serialization, array $shared_protected_header = [], array $shared_unprotected_header = [], $aad = null) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Encrypt an input and convert it into a JWE JSON (Compact/Flattened) Serialized representation. |
||
| 76 | * |
||
| 77 | * To encrypt the input using different algorithms, the "alg" parameter must be set in the unprotected header of the $instruction. |
||
| 78 | * Please note that this is not possible when using the algorithms "dir" or "ECDH-ES". |
||
| 79 | * |
||
| 80 | * @param \Jose\Object\JWTInterface|\Jose\Object\JWKInterface|\Jose\Object\JWKSetInterface|array|string $input A JWKInterface/JWKInterface/JWKSetInterface object |
||
| 81 | * @param \Jose\Object\EncryptionInstructionInterface[] $instructions A list of instructions used to encrypt the input |
||
| 82 | * @param array $shared_protected_header Shared protected headers. If the input is a JWTInterface object, this parameter is merged with the protected header of the input. |
||
| 83 | * @param array $shared_unprotected_header Shared unprotected headers. If the input is a JWTInterface object, this parameter is merged with the unprotected header of the input. |
||
| 84 | * @param string $serialization Serialization method. |
||
| 85 | * @param string|null $aad Additional Authentication Data. This parameter is useless if the serialization is JSON_COMPACT_SERIALIZATION. |
||
| 86 | * |
||
| 87 | * @throws \Exception |
||
| 88 | * |
||
| 89 | * @return string|string[] The JSON (Compact/Flattened) Serialized representation |
||
| 90 | */ |
||
| 91 | View Code Duplication | private function encryptData($input, array $instructions, $serialization, array $shared_protected_header = [], array $shared_unprotected_header = [], $aad = null) |
|
| 103 | } |
||
| 104 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.