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 |
||
20 | class UserListClientService implements CacheableInterface |
||
21 | { |
||
22 | use CachableTrait; |
||
23 | |||
24 | const API_VERSION = 'v201708'; |
||
25 | |||
26 | const URL_LIST_CLIENT = 'https://ddp.googleapis.com/api/ddp/provider/v201708/UserListClientService?wsdl'; |
||
27 | const USER_LIST_CLIENT_TPL = 'userListClient.xml.twig'; |
||
28 | const GET_USER_CLIENT_LIST_TPL = 'getUserClientList.xml.twig'; |
||
29 | |||
30 | /** |
||
31 | * @var Client|Auth |
||
32 | */ |
||
33 | protected $client; |
||
34 | |||
35 | /** |
||
36 | * @var Cache |
||
37 | */ |
||
38 | protected $cache; |
||
39 | |||
40 | /** |
||
41 | * @var TwigCompiler |
||
42 | */ |
||
43 | protected $twigCompiler; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $clientCustomerId; |
||
49 | |||
50 | /** |
||
51 | * UserListClient constructor. |
||
52 | * @param Auth|Client $client |
||
53 | * @param Cache $cache |
||
54 | * @param TwigCompiler $twigCompiler |
||
55 | * @param string $clientCustomerId |
||
56 | */ |
||
57 | View Code Duplication | public function __construct($client, Cache $cache = null, TwigCompiler $twigCompiler, $clientCustomerId) |
|
64 | |||
65 | /** |
||
66 | * @param UserListClient $client |
||
67 | * @param bool $updateIfExist |
||
68 | * @return UserListClient |
||
69 | * @throws ClientException |
||
70 | */ |
||
71 | public function createUserClientList(UserListClient $client, $updateIfExist = false) |
||
120 | |||
121 | |||
122 | /** |
||
123 | * @param null $userListId |
||
124 | * @param null $clientId |
||
125 | * @return UserListClient[]|UserListClient |
||
126 | * @throws ClientException |
||
127 | */ |
||
128 | public function getUserClientList($userListId = null, $clientId = null) |
||
170 | } |
||
171 |
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.