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 |
||
17 | class FBUser |
||
18 | { |
||
19 | |||
20 | protected $config = []; |
||
21 | protected $client = null; |
||
22 | |||
23 | /** |
||
24 | * Message constructor. |
||
25 | * @param array $config |
||
26 | */ |
||
27 | 28 | View Code Duplication | public function __construct(array $config, Client $client) |
28 | { |
||
29 | |||
30 | 28 | $this->client = $client; |
|
31 | |||
32 | 28 | if ($this->checkConfig($config) && !empty($client)) { |
|
33 | 24 | $this->config = $config; |
|
34 | 18 | } else { |
|
35 | 4 | throw new ConfigException(trans('messenger::errors.config_not_valid')); |
|
36 | } |
||
37 | |||
38 | 18 | } |
|
39 | |||
40 | /** |
||
41 | * @return array |
||
42 | */ |
||
43 | 4 | public function getConfig() |
|
47 | |||
48 | /** |
||
49 | * @return Client|null |
||
50 | */ |
||
51 | 4 | public function getClient() |
|
55 | |||
56 | |||
57 | 28 | protected function checkConfig(array $config) |
|
61 | |||
62 | |||
63 | 16 | public function getProfile($uid, $fields = ['fields' => 'first_name,last_name,profile_pic,locale,timezone,gender']) |
|
68 | |||
69 | |||
70 | 16 | public function callSendAPI($uid, $data) |
|
87 | |||
88 | } |