StoresService   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 110
Duplicated Lines 41.82 %

Importance

Changes 0
Metric Value
dl 46
loc 110
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A updateStores() 22 22 2
A listStores() 0 10 1
A deleteStores() 0 15 2
A createStores() 22 22 2
A __construct() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

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
2
3
/*
4
 * This file is part of PHP CS Fixer.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *     Dariusz Rumiński <[email protected]>
8
 *
9
 * This source file is subject to the MIT license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Etrias\PaazlConnector\Services;
14
15
use DateTime;
16
use Etrias\PaazlConnector\Client\PaazlClientInterface;
17
use Etrias\PaazlConnector\SoapTypes\ChangeStoreDetailsType;
18
use Etrias\PaazlConnector\SoapTypes\ChangeStoresRequestType;
19
use Etrias\PaazlConnector\SoapTypes\DeleteStoresRequest;
20
use Etrias\PaazlConnector\SoapTypes\DeleteStoreType;
21
use Etrias\PaazlConnector\SoapTypes\ListStoresRequest;
22
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
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
77
    {
78
        $changeStores = [];
79
        foreach ($stores as $store) {
80
            $changeStore = new ChangeStoreDetailsType(
81
                $this->security->getHash($store->getCode()),
82
                $store->getCode(),
83
                $store->getName(),
84
                $store->getAddress(),
85
                $store->getCoordinates(),
86
                $store->getBusinessHours()
87
            );
88
            $changeStores[] = $changeStore;
89
        }
90
91
        $request = new ChangeStoresRequestType(
92
            $this->client->getWebShopId(),
93
            $targetWebShop,
94
            $changeStores
95
        );
96
97
        return $this->client->updateStores($request);
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)
124
    {
125
        $today = new DateTime();
126
        $request = new ListStoresRequest(
127
            $this->security->getHash($today->format('Ymd')),
128
            $this->client->getWebShopId(),
129
            $targetWebShop
130
        );
131
132
        return $this->client->listStores($request);
133
    }
134
}
135