ListService   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 143
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 143
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAddress() 0 13 1
B getServicePoints() 0 44 5
B getDeliveryEstimate() 0 32 1
A __construct() 0 4 1
A getRates() 0 13 1
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 Etrias\PaazlConnector\Client\PaazlClientInterface;
16
use Etrias\PaazlConnector\SoapTypes\AddressRequest;
17
use Etrias\PaazlConnector\SoapTypes\CoordinatesType;
18
use Etrias\PaazlConnector\SoapTypes\DeliveryEstimateRequest;
19
use Etrias\PaazlConnector\SoapTypes\RateRequest;
20
use Etrias\PaazlConnector\SoapTypes\ServicePointsRequest;
21
use RuntimeException;
22
23
class ListService implements ListServiceInterface
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
    public function getAddress($orderReference, $zipCode, $houseNumber, $addition = null, $targetWebShop = null)
50
    {
51
        $request = new AddressRequest(
52
            $this->security->getHash($orderReference),
53
            $this->client->getWebShopId(),
54
            $targetWebShop,
55
            $orderReference,
56
            $zipCode,
57
            $houseNumber,
58
            $addition
59
        );
60
61
        return $this->client->address($request);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getDeliveryEstimate(
68
        $orderReference,
69
        $weight,
70
        $value,
71
        $valueCurrency,
72
        $consigneeCountry,
73
        $consigneeCity,
74
        $consigneePostcode,
75
        $shippingOption = null,
76
        $senderCountry = null,
77
        $senderCity = null,
78
        $senderPostcode = null,
79
        $targetWebShop = null)
80
    {
81
        $request = new DeliveryEstimateRequest(
82
            $this->security->getHash($orderReference),
83
            $this->client->getWebShopId(),
84
            $targetWebShop,
85
            $orderReference,
86
            $shippingOption,
87
            $weight,
88
            $value,
89
            $valueCurrency,
90
            $senderCountry,
91
            $senderCity,
92
            $senderPostcode,
93
            $consigneeCountry,
94
            $consigneeCity,
95
            $consigneePostcode
96
        );
97
98
        return $this->client->deliveryEstimate($request);
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function getRates($orderReference, $country = null, $postalCode = null, $shippingOption = null, $targetWebShop = null)
105
    {
106
        $request = new RateRequest(
107
            $this->security->getHash($orderReference),
108
            $this->client->getWebShopId(),
109
            $targetWebShop,
110
            $orderReference,
111
            $country,
112
            $postalCode,
113
            $shippingOption
114
        );
115
116
        return $this->client->rate($request);
117
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122
    public function getServicePoints(
123
        $country = null,
124
        $postcode = null,
125
        CoordinatesType $southWest = null,
126
        CoordinatesType $northEast = null,
127
        $limit = null,
128
        $shippingOption = null,
129
        $evening = null,
130
        $weekend = null,
131
        $targetWebShop = null
132
    ) {
133
        $hashInput = '';
134
135
        if ($country !== null) {
136
            $hashInput .= $country;
137
        }
138
139
        if ($postcode !== null) {
140
            $hashInput .= $postcode;
141
        }
142
143
        if ($southWest !== null) {
144
            throw new RuntimeException('Not yet implemented');
145
        }
146
147
        if ($northEast !== null) {
148
            throw new RuntimeException('Not yet implemented');
149
        }
150
151
        $request = new ServicePointsRequest(
152
            $this->security->getHash($hashInput),
153
            $this->client->getWebShopId(),
154
            $targetWebShop,
155
            $shippingOption,
156
            $evening,
157
            $weekend,
158
            $country,
159
            $postcode,
160
            $limit,
161
            $southWest,
162
            $northEast
163
        );
164
165
        return $this->client->servicePoints($request);
166
    }
167
}
168