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 BaseLinodeApi |
||
20 | { |
||
21 | /** @var string API key */ |
||
22 | protected $key; |
||
23 | |||
24 | /** @var \Linode\Batch */ |
||
25 | protected $batch; |
||
26 | |||
27 | /** @var array Additional cURL options. */ |
||
28 | protected $options; |
||
29 | |||
30 | /** @var bool Whether the object is in debug mode */ |
||
31 | protected $debug; |
||
32 | |||
33 | /** |
||
34 | * Constructor. |
||
35 | * |
||
36 | * @param string|Batch $key API key, or batch of requests |
||
37 | * @param array $options Additional cURL options to be set. |
||
38 | * @param bool $debug Whether the object should be in debug mode |
||
39 | */ |
||
40 | 72 | public function __construct($key, array $options = [], $debug = false) |
|
53 | |||
54 | /** |
||
55 | * Performs specified call to Linode API. |
||
56 | * |
||
57 | * @param string $action |
||
58 | * @param array $parameters |
||
59 | * |
||
60 | * @return array|bool |
||
61 | * |
||
62 | * @throws LinodeException |
||
63 | * @throws \Exception |
||
64 | */ |
||
65 | 72 | protected function call($action, array $parameters = []) |
|
125 | } |
||
126 |
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.