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 |
||
| 32 | final class Signer implements SignerInterface |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * @var null|\SpomkyLabs\JoseBundle\Model\JotManagerInterface |
||
| 36 | */ |
||
| 37 | private $jot_manager; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var \Jose\Signer |
||
| 41 | */ |
||
| 42 | private $signer; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Signer constructor. |
||
| 46 | * |
||
| 47 | * @param \Jose\Algorithm\JWAManagerInterface $jwa_manager |
||
| 48 | * @param \Jose\Payload\PayloadConverterManagerInterface $payload_converter_manager |
||
| 49 | * @param \SpomkyLabs\JoseBundle\Model\JotManagerInterface|null $jot_manager |
||
| 50 | */ |
||
| 51 | public function __construct(JWAManagerInterface $jwa_manager, |
||
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritdoc} |
||
| 61 | */ |
||
| 62 | public function sign($input, array $instructions, $serialization, $detached_signature = false, &$detached_payload = null) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Sign an input and convert it into JWS JSON (Compact/Flattened) Serialized representation. |
||
| 82 | * |
||
| 83 | * @param \Jose\Object\JWKInterface|\Jose\Object\JWKSetInterface|string|array $input A JWKInterface/JWKInterface/JWKSetInterface object |
||
| 84 | * @param \Jose\Object\SignatureInstructionInterface[] $instructions A list of instructions used to sign the input |
||
| 85 | * @param string $serialization Serialization method. If the argument $keys contains more than one private key and value is JSON_COMPACT_SERIALIZATION or JSON_FLATTENED_SERIALIZATION, the result will be an array of JWT. |
||
| 86 | * @param bool $detached_signature If true, the payload will be detached and variable $detached_payload will be set |
||
| 87 | * @param null|string $detached_payload The detached payload encoded in Base64 URL safe |
||
| 88 | * |
||
| 89 | * @throws \Exception |
||
| 90 | * |
||
| 91 | * @return string|string[] The JSON (Compact/Flattened) Serialized representation |
||
| 92 | */ |
||
| 93 | View Code Duplication | private function signData($input, array $instructions, $serialization, $detached_signature = false, &$detached_payload = null) |
|
| 105 | |||
| 106 | /** |
||
| 107 | * @param \Jose\Object\SignatureInstructionInterface[] $instructions A list of instructions used to sign the input |
||
| 108 | * @param \SpomkyLabs\JoseBundle\Model\JotInterface $jot |
||
| 109 | |||
| 110 | * @return \Jose\Object\SignatureInstructionInterface[] |
||
| 111 | */ |
||
| 112 | private function getNewInstructions(array $instructions, JotInterface $jot) |
||
| 128 | } |
||
| 129 |
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.