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 |
||
21 | class ChronosApiClient implements ApiClientInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var HttpClientInterface |
||
25 | */ |
||
26 | private $httpClient; |
||
27 | |||
28 | /** |
||
29 | * @param HttpClientInterface $httpClient |
||
30 | */ |
||
31 | 21 | public function __construct( |
|
36 | |||
37 | /** |
||
38 | * @inheritdoc |
||
39 | * @link: https://mesos.github.io/chronos/docs/api.html#listing-jobs |
||
40 | */ |
||
41 | 2 | public function listingJobs() |
|
45 | |||
46 | /** |
||
47 | * @param JobEntityInterface $jobEntity |
||
48 | * @return bool |
||
49 | * @throws ApiClientException |
||
50 | */ |
||
51 | 10 | public function addingJob(JobEntityInterface $jobEntity) |
|
72 | |||
73 | /** |
||
74 | * @param JobEntityInterface|ChronosJobEntity $jobEntity |
||
75 | * @return bool |
||
76 | * @throws ApiClientException |
||
77 | */ |
||
78 | 5 | public function updatingJob(JobEntityInterface $jobEntity) |
|
82 | |||
83 | /** |
||
84 | * @param string $jobName |
||
85 | * @return bool |
||
86 | */ |
||
87 | 2 | public function removeJob($jobName) |
|
92 | |||
93 | /** |
||
94 | * @inheritdoc |
||
95 | */ |
||
96 | 2 | public function getJobStats($jobName) |
|
100 | |||
101 | /** |
||
102 | * @param string $url |
||
103 | * @return array |
||
104 | */ |
||
105 | 4 | View Code Duplication | private function sendGetJsonRequest($url) |
114 | |||
115 | /** |
||
116 | * Returns true if the client can be connected to. |
||
117 | * @return bool |
||
118 | */ |
||
119 | 5 | View Code Duplication | public function ping() |
133 | } |
||
134 |