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 |
||
| 15 | class Request extends AbstractRequest |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var TransportInterface This is how |
||
| 19 | * you will point to Paybox (via cURL or Shell) |
||
| 20 | */ |
||
| 21 | protected $transport; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Constructor. |
||
| 25 | * |
||
| 26 | * @param array $parameters |
||
| 27 | * @param array $servers |
||
| 28 | * @param TransportInterface $transport |
||
| 29 | */ |
||
| 30 | public function __construct(array $parameters, array $servers, TransportInterface $transport = null) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc} |
||
| 39 | */ |
||
| 40 | View Code Duplication | protected function initGlobals(array $parameters) |
|
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritdoc} |
||
| 56 | */ |
||
| 57 | protected function initParameters() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Returns all parameters set for a payment. |
||
| 68 | * |
||
| 69 | * @return array |
||
| 70 | */ |
||
| 71 | View Code Duplication | public function getParameters() |
|
| 82 | |||
| 83 | /** |
||
| 84 | * {@inheritdoc} |
||
| 85 | */ |
||
| 86 | public function getUrl() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * {@inheritDoc} |
||
| 100 | * |
||
| 101 | * @param string $reference |
||
| 102 | * @param string $subscriptionId |
||
| 103 | * |
||
| 104 | * @throws \RuntimeException On cURL error |
||
| 105 | * |
||
| 106 | * @return string The html of the temporary form |
||
| 107 | */ |
||
| 108 | public function cancel($reference = null, $subscriptionId = null) |
||
| 122 | } |
||
| 123 |
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.