Passed
Push — master ( 14d404...4bd91f )
by C.
02:09
created

PickupService::createPickupRequest()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 49
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 9.2258
c 0
b 0
f 0
cc 2
eloc 25
nc 1
nop 17

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\Service;
14
15
use DateTime;
16
use Etrias\PaazlConnector\Processor\Processor;
17
use Etrias\PaazlConnector\ServiceType\Service as GeneralServiceType;
18
use Etrias\PaazlConnector\StructType\AddressType;
19
use Etrias\PaazlConnector\StructType\CancelPickupRequestResponse;
20
use Etrias\PaazlConnector\StructType\CreatePickupRequestRequest;
21
use Etrias\PaazlConnector\StructType\CreatePickupRequestResponse;
22
use Etrias\PaazlConnector\StructType\PickupRequestDetailsResponse;
23
use Etrias\PaazlConnector\StructType\PickupRequestOptionsRequest;
24
use Etrias\PaazlConnector\StructType\PickupRequestQueryType;
25
use InvalidArgumentException;
26
27
class PickupService
28
{
29
    use Processor;
30
31
    /**
32
     * @var SecurityServiceInterface
33
     */
34
    protected $securityService;
35
    /**
36
     * @var GeneralServiceType
37
     */
38
    protected $generalServiceType;
39
40
    /**
41
     * DocumentService constructor.
42
     *
43
     * @param GeneralServiceType       $generalServiceType
44
     * @param SecurityServiceInterface $securityService
45
     */
46
    public function __construct(GeneralServiceType $generalServiceType, SecurityServiceInterface $securityService)
47
    {
48
        $this->securityService = $securityService;
49
        $this->generalServiceType = $generalServiceType;
50
    }
51
52
    /**
53
     * @param $internalReference
54
     * @param null $pickupCountry
55
     * @param null $deliveryCountry
56
     * @param null $targetWebShop
57
     *
58
     * @return PickupRequestDetailsResponse
59
     */
60 View Code Duplication
    public function getPickupRequestOptions($internalReference, $pickupCountry = null, $deliveryCountry = null, $targetWebShop = null)
61
    {
62
        $request = new PickupRequestOptionsRequest(
63
            $this->securityService->getHash($internalReference),
64
            $this->generalServiceType->getWebShopId(),
65
            $targetWebShop,
66
            $internalReference,
67
            $pickupCountry,
68
            $deliveryCountry
69
        );
70
71
        $response = $this->generalServiceType->pickupRequestOptions($request);
72
73
        return $this->processResponse($response, $this->generalServiceType);
74
    }
75
76
    /**
77
     * @param $internalReference
78
     * @param $pickupRequestOption
79
     * @param $pieceCount
80
     * @param DateTime $pickupWindowStart
81
     * @param DateTime $pickupWindowEnd
82
     * @param $pickupCompanyName
83
     * @param $pickupContactName
84
     * @param $pickupName
85
     * @param AddressType $pickupAddress
86
     * @param $pickupPhoneNumber
87
     * @param null             $pickupEmailAddress
88
     * @param AddressType|null $deliveryAddress
89
     * @param null             $deliveryEmailAddress
90
     * @param null             $additionalInstruction
91
     * @param null             $orderReference
92
     * @param null             $contract
93
     * @param null             $targetWebShop
94
     *
95
     * @return CreatePickupRequestResponse
96
     */
97
    public function createPickupRequest(
98
        $internalReference,
99
        $pickupRequestOption,
100
        $pieceCount,
101
        DateTime $pickupWindowStart,
102
        DateTime $pickupWindowEnd,
103
        $pickupCompanyName,
104
        $pickupContactName,
105
        $pickupName,
106
        AddressType $pickupAddress,
107
        $pickupPhoneNumber,
108
        $pickupEmailAddress = null,
109
        AddressType $deliveryAddress = null,
110
        $deliveryEmailAddress = null,
111
        $additionalInstruction = null,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $additionalInstruction exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
112
        $orderReference = null,
113
        $contract = null,
114
        $targetWebShop = null
115
    ) {
116
        if ($pickupWindowStart->format('Y-m-d') !== $pickupWindowEnd->format('Y-m-d')) {
117
            throw new InvalidArgumentException('pickupWindowStart and pickupWindowEnd should be on the same day');
118
        }
119
120
        $request = new CreatePickupRequestRequest(
121
            $this->securityService->getHash($internalReference),
122
            $this->generalServiceType->getWebShopId(),
123
            $targetWebShop,
124
            $internalReference,
125
            $contract,
126
            $pickupRequestOption,
127
            $orderReference,
128
            $pieceCount,
129
            $pickupWindowStart->format('Y-m-d'),
130
            $pickupWindowStart->format('H:i:s'),
131
            $pickupWindowEnd->format('H:i:s'),
132
            $pickupCompanyName,
133
            $pickupContactName,
134
            $pickupName,
135
            $pickupAddress,
136
            $pickupPhoneNumber,
137
            $pickupEmailAddress,
138
            $deliveryAddress,
139
            $deliveryEmailAddress,
140
            $additionalInstruction
141
        );
142
143
        $response = $this->generalServiceType->createPickupRequest($request);
144
145
        return $this->processResponse($response, $this->generalServiceType);
146
    }
147
148
    /**
149
     * @param $internalReference
150
     * @param $distributor
151
     * @param $externalReference
152
     * @param null $targetWebShop
153
     *
154
     * @return PickupRequestDetailsResponse
155
     */
156
    public function getPickupRequestDetails($internalReference, $distributor, $externalReference, $targetWebShop = null)
157
    {
158
        $request = new PickupRequestQueryType(
159
            $this->securityService->getHash($internalReference),
160
            $this->generalServiceType->getWebShopId(),
161
            $targetWebShop,
162
            $internalReference,
163
            $distributor,
164
            $externalReference
165
        );
166
167
        $response = $this->generalServiceType->pickupRequestDetails($request);
168
169
        return $this->processResponse($response, $this->generalServiceType);
170
    }
171
172
    /**
173
     * @param $internalReference
174
     * @param $distributor
175
     * @param $externalReference
176
     * @param null $targetWebShop
177
     *
178
     * @return PickupRequestStatusResponse
0 ignored issues
show
Bug introduced by
The type Etrias\PaazlConnector\Se...upRequestStatusResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
179
     */
180
    public function getPickupRequestStatus($internalReference, $distributor, $externalReference, $targetWebShop = null)
181
    {
182
        $request = new PickupRequestQueryType(
183
            $this->securityService->getHash($internalReference),
184
            $this->generalServiceType->getWebShopId(),
185
            $targetWebShop,
186
            $internalReference,
187
            $distributor,
188
            $externalReference
189
        );
190
191
        $response = $this->generalServiceType->pickupRequestStatus($request);
192
193
        return $this->processResponse($response, $this->generalServiceType);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->processRes...is->generalServiceType) returns the type WsdlToPhp\PackageBase\Ab...Base\AbstractStructBase which is incompatible with the documented return type Etrias\PaazlConnector\Se...upRequestStatusResponse.
Loading history...
194
    }
195
196
    /**
197
     * @param $internalReference
198
     * @param $distributor
199
     * @param $externalReference
200
     * @param null $targetWebShop
201
     *
202
     * @return CancelPickupRequestResponse
203
     */
204
    public function cancelPickupRequest($internalReference, $distributor, $externalReference, $targetWebShop = null)
205
    {
206
        $request = new PickupRequestQueryType(
207
            $this->securityService->getHash($internalReference),
208
            $this->generalServiceType->getWebShopId(),
209
            $targetWebShop,
210
            $internalReference,
211
            $distributor,
212
            $externalReference
213
        );
214
215
        $response = $this->generalServiceType->cancelPickupRequest($request);
216
217
        return $this->processResponse($response, $this->generalServiceType);
218
    }
219
}
220