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 |
||
| 19 | class Request extends AbstractRequest |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var FormFactoryInterface |
||
| 23 | */ |
||
| 24 | protected $factory; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Constructor. |
||
| 28 | * |
||
| 29 | * @param array $parameters |
||
| 30 | * @param array $servers |
||
| 31 | * @param FormFactoryInterface $factory |
||
| 32 | * |
||
| 33 | * @throws InvalidConfigurationException If the hash_hmac() function of PECL hash is not available. |
||
| 34 | */ |
||
| 35 | public function __construct(array $parameters, array $servers, FormFactoryInterface $factory) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * {@inheritdoc} |
||
| 48 | */ |
||
| 49 | View Code Duplication | protected function initGlobals(array $parameters) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | protected function initParameters() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Sets a parameter. |
||
| 76 | * |
||
| 77 | * @param string $name |
||
| 78 | * @param mixed $value |
||
| 79 | * |
||
| 80 | * @return Request |
||
| 81 | */ |
||
| 82 | public function setParameter($name, $value) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Parameter PBX_RETOUR must contain the string ";Sign:K" at the end for ipn signature verification. |
||
| 96 | * |
||
| 97 | * @param string $value |
||
| 98 | * |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | protected function verifyReturnParameter($value) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Returns all parameters set for a payment. |
||
| 124 | * |
||
| 125 | * @return array |
||
| 126 | */ |
||
| 127 | View Code Duplication | public function getParameters() |
|
| 138 | |||
| 139 | /** |
||
| 140 | * Returns a form with defined parameters. |
||
| 141 | * |
||
| 142 | * @param array $options |
||
| 143 | * |
||
| 144 | * @return Form |
||
| 145 | */ |
||
| 146 | public function getForm($options = array()) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * {@inheritdoc} |
||
| 175 | */ |
||
| 176 | public function getUrl() |
||
| 187 | } |
||
| 188 |
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.