PickupService   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 141
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPickupRequestOptions() 0 12 1
A getPickupRequestStatus() 0 12 1
A createPickupRequest() 0 47 2
A getPickupRequestDetails() 0 12 1
A cancelPickupRequest() 0 12 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 DateTime;
16
use Etrias\PaazlConnector\Client\PaazlClientInterface;
17
use Etrias\PaazlConnector\SoapTypes\AddressType;
18
use Etrias\PaazlConnector\SoapTypes\CreatePickupRequestRequest;
19
use Etrias\PaazlConnector\SoapTypes\PickupRequestOptionsRequest;
20
use Etrias\PaazlConnector\SoapTypes\PickupRequestQueryType;
21
use InvalidArgumentException;
22
23
class PickupService implements PickupServiceInterface
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 getPickupRequestOptions($internalReference, $pickupCountry = null, $deliveryCountry = null, $targetWebShop = null)
50
    {
51
        $request = new PickupRequestOptionsRequest(
52
            $this->security->getHash($internalReference),
53
            $this->client->getWebShopId(),
54
            $targetWebShop,
55
            $internalReference,
56
            $pickupCountry,
57
            $deliveryCountry
58
        );
59
60
        return $this->client->pickupRequestOptions($request);
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function createPickupRequest(
67
        $internalReference,
68
        $pickupRequestOption,
69
        $pieceCount,
70
        DateTime $pickupWindowStart,
71
        DateTime $pickupWindowEnd,
72
        $pickupCompanyName,
73
        $pickupContactName,
74
        $pickupName,
75
        AddressType $pickupAddress,
76
        $pickupPhoneNumber,
77
        $pickupEmailAddress = null,
78
        AddressType $deliveryAddress = null,
79
        $deliveryEmailAddress = null,
80
        $additionalInstruction = null,
81
        $orderReference = null,
82
        $contract = null,
83
        $targetWebShop = null
84
    ) {
85
        if ($pickupWindowStart->format('Y-m-d') !== $pickupWindowEnd->format('Y-m-d')) {
86
            throw new InvalidArgumentException('pickupWindowStart and pickupWindowEnd should be on the same day');
87
        }
88
89
        $request = new CreatePickupRequestRequest(
90
            $this->security->getHash($internalReference),
91
            $this->client->getWebShopId(),
92
            $targetWebShop,
93
            $internalReference,
94
            $contract,
95
            $pickupRequestOption,
96
            $orderReference,
97
            $pieceCount,
98
            $pickupWindowStart,
99
            $pickupWindowStart->format('H:i:s'),
100
            $pickupWindowEnd->format('H:i:s'),
101
            $pickupCompanyName,
102
            $pickupContactName,
103
            $pickupName,
104
            $pickupAddress,
105
            $pickupPhoneNumber,
106
            $pickupEmailAddress,
107
            $deliveryAddress,
108
            $deliveryEmailAddress,
109
            $additionalInstruction
110
        );
111
112
        return $this->client->createPickupRequest($request);
113
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118
    public function getPickupRequestDetails($internalReference, $distributor, $externalReference, $targetWebShop = null)
119
    {
120
        $request = new PickupRequestQueryType(
121
            $this->security->getHash($internalReference),
122
            $this->client->getWebShopId(),
123
            $targetWebShop,
124
            $internalReference,
125
            $distributor,
126
            $externalReference
127
        );
128
129
        return $this->client->pickupRequestDetails($request);
130
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135
    public function getPickupRequestStatus($internalReference, $distributor, $externalReference, $targetWebShop = null)
136
    {
137
        $request = new PickupRequestQueryType(
138
            $this->security->getHash($internalReference),
139
            $this->client->getWebShopId(),
140
            $targetWebShop,
141
            $internalReference,
142
            $distributor,
143
            $externalReference
144
        );
145
146
        return $this->client->pickupRequestStatus($request);
147
    }
148
149
    /**
150
     * {@inheritdoc}
151
     */
152
    public function cancelPickupRequest($internalReference, $distributor, $externalReference, $targetWebShop = null)
153
    {
154
        $request = new PickupRequestQueryType(
155
            $this->security->getHash($internalReference),
156
            $this->client->getWebShopId(),
157
            $targetWebShop,
158
            $internalReference,
159
            $distributor,
160
            $externalReference
161
        );
162
163
        return $this->client->cancelPickupRequest($request);
164
    }
165
}
166