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 |
||
| 16 | class ParameterResolver extends AbstractParameterResolver |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var array All availables parameters DirectPlus calls. |
||
| 20 | */ |
||
| 21 | private $knownParameters = array( |
||
| 22 | 'VERSION' => '%05d', |
||
| 23 | 'TYPE' => '%05d', |
||
| 24 | 'SITE' => '%07d', |
||
| 25 | 'RANG' => '%03d', |
||
| 26 | 'CLE' => '%s', |
||
| 27 | 'NUMQUESTION' => '%010d', |
||
| 28 | 'DATEQ' => '%014s', |
||
| 29 | 'ACQUEREUR' => null, |
||
| 30 | 'ACTIVITE' => '%03d', |
||
| 31 | 'ARCHIVAGE' => null, |
||
| 32 | 'AUTORISATION' => null, |
||
| 33 | 'CODEREPONSE' => null, |
||
| 34 | 'COMMENTAIRE' => null, |
||
| 35 | 'CVV' => null, |
||
| 36 | 'DATENAISS' => '%08d', |
||
| 37 | 'DATEVAL' => null, |
||
| 38 | 'DEVISE' => null, |
||
| 39 | 'DIFFERE' => '%03d', |
||
| 40 | 'ERRORCODETEST' => '%05d', |
||
| 41 | 'ID3D' => null, |
||
| 42 | 'MONTANT' => '%010d', |
||
| 43 | 'NUMAPPEL' => '%010d', |
||
| 44 | 'NUMTRANS' => '%010d', |
||
| 45 | 'PAYS' => null, |
||
| 46 | 'PORTEUR' => null, |
||
| 47 | 'PRIV_CODETRAITEMENT' => '%03d', |
||
| 48 | 'REFABONNE' => null, |
||
| 49 | 'REFERENCE' => null, |
||
| 50 | 'REMISE' => null, |
||
| 51 | 'SHA-1' => null, |
||
| 52 | 'STATUS' => null, |
||
| 53 | 'TYPECARTE' => null, |
||
| 54 | ); |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var array Requireds parameters for any DirectPlus call. |
||
| 58 | */ |
||
| 59 | private $requiredParameters = array( |
||
| 60 | 'VERSION', |
||
| 61 | 'TYPE', |
||
| 62 | 'SITE', |
||
| 63 | 'RANG', |
||
| 64 | 'CLE', |
||
| 65 | 'NUMQUESTION', |
||
| 66 | 'DATEQ', |
||
| 67 | ); |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var array |
||
| 71 | */ |
||
| 72 | private $currencies; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Constructor initialize all available parameters. |
||
| 76 | * |
||
| 77 | * @param array $currencies |
||
| 78 | */ |
||
| 79 | public function __construct(array $currencies) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * {@inheritdoc} |
||
| 88 | */ |
||
| 89 | public function resolve(array $parameters) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * {@inheritdoc} |
||
| 101 | */ |
||
| 102 | View Code Duplication | protected function initResolver() |
|
| 110 | |||
| 111 | /** |
||
| 112 | * Initialize allowed values. |
||
| 113 | */ |
||
| 114 | protected function initAllowed() |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Normalizes parameters depending on Paybox's 6.2 parameters specifications. |
||
| 183 | * |
||
| 184 | * @param array $parameters |
||
| 185 | * |
||
| 186 | * @return array |
||
| 187 | */ |
||
| 188 | protected function normalize(array $parameters) |
||
| 198 | } |
||
| 199 |
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.