Total Complexity | 8 |
Total Lines | 110 |
Duplicated Lines | 41.82 % |
Changes | 0 |
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 |
||
23 | class StoresService implements StoresServiceInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var PaazlClientInterface |
||
27 | */ |
||
28 | protected $client; |
||
29 | /** |
||
30 | * @var SecurityServiceInterface |
||
31 | */ |
||
32 | protected $security; |
||
33 | |||
34 | /** |
||
35 | * DocumentService constructor. |
||
36 | * |
||
37 | * @param PaazlClientInterface $client |
||
38 | * @param SecurityServiceInterface $security |
||
39 | */ |
||
40 | public function __construct(PaazlClientInterface $client, SecurityServiceInterface $security) |
||
41 | { |
||
42 | $this->security = $security; |
||
43 | $this->client = $client; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | View Code Duplication | public function createStores(array $stores, $targetWebShop = null) |
|
1 ignored issue
–
show
|
|||
50 | { |
||
51 | $changeStores = []; |
||
52 | foreach ($stores as $store) { |
||
53 | $changeStore = new ChangeStoreDetailsType( |
||
54 | $this->security->getHash($store->getCode()), |
||
55 | $store->getCode(), |
||
56 | $store->getName(), |
||
57 | $store->getAddress(), |
||
58 | $store->getCoordinates(), |
||
59 | $store->getBusinessHours() |
||
60 | ); |
||
61 | $changeStores[] = $changeStore; |
||
62 | } |
||
63 | |||
64 | $request = new ChangeStoresRequestType( |
||
65 | $this->client->getWebShopId(), |
||
66 | $targetWebShop, |
||
67 | $changeStores |
||
68 | ); |
||
69 | |||
70 | return $this->client->createStores($request); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | View Code Duplication | public function updateStores(array $stores, $targetWebShop = null) |
|
98 | } |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function deleteStores(array $storeCodes, $targetWebShop = null) |
||
104 | { |
||
105 | $stores = []; |
||
106 | |||
107 | foreach ($storeCodes as $storeCode) { |
||
108 | $stores[] = new DeleteStoreType($this->security->getHash($storeCode), $storeCode); |
||
109 | } |
||
110 | |||
111 | $request = new DeleteStoresRequest( |
||
112 | $this->client->getWebShopId(), |
||
113 | $targetWebShop, |
||
114 | $stores |
||
115 | ); |
||
116 | |||
117 | return $this->client->deleteStores($request); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | public function listStores($targetWebShop = null) |
||
133 | } |
||
134 | } |
||
135 |
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.