GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DetailItem   A
last analyzed

Complexity

Total Complexity 27

Size/Duplication

Total Lines 290
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 27
c 2
b 0
f 1
lcom 1
cbo 4
dl 0
loc 290
rs 10

23 Methods

Rating   Name   Duplication   Size   Complexity  
A getDeliveryWindowFromDate() 0 4 1
A getDeliveryWindowToDate() 0 4 1
A getShippingWindowFromDate() 0 4 1
A getShippingWindowToDate() 0 4 1
A getDeliveryEstimateCreationTime() 0 4 1
A getDeliveryEstimateDisplayFlag() 0 4 1
A getDeliveryEstimateMessage() 0 4 1
A deserializeExtra() 0 16 4
A getPhysicalAddressRootNodeName() 0 4 1
A getRootNodeName() 0 4 1
A getXmlNamespace() 0 4 1
B __construct() 0 38 1
A setDeliveryWindowFromDate() 0 5 1
A setDeliveryWindowToDate() 0 5 1
A setShippingWindowFromDate() 0 5 1
A setShippingWindowToDate() 0 5 1
A setDeliveryEstimateCreationTime() 0 5 1
A setDeliveryEstimateDisplayFlag() 0 5 1
A setDeliveryEstimateMessage() 0 5 1
A serializeContents() 0 5 1
A serializeDeliveryEstimate() 0 16 1
A serializeDateTime() 0 5 2
A getRootAttributes() 0 7 1
1
<?php
2
/**
3
 * Copyright (c) 2013-2014 eBay Enterprise, Inc.
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * This source file is subject to the Open Software License (OSL 3.0)
8
 * that is bundled with this package in the file LICENSE.md.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * @copyright   Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/)
13
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
14
 */
15
16
namespace eBayEnterprise\RetailOrderManagement\Payload\Inventory;
17
18
use eBayEnterprise\RetailOrderManagement\Payload\IPayload;
19
use eBayEnterprise\RetailOrderManagement\Payload\IPayloadMap;
20
use eBayEnterprise\RetailOrderManagement\Payload\ISchemaValidator;
21
use eBayEnterprise\RetailOrderManagement\Payload\IValidatorIterator;
22
use eBayEnterprise\RetailOrderManagement\Payload\PayloadFactory;
23
use eBayEnterprise\RetailOrderManagement\Payload\TPayload;
24
use eBayEnterprise\RetailOrderManagement\Payload\Checkout\TPhysicalAddress;
25
use Psr\Log\LoggerInterface;
26
use \DateTime;
27
28
/**
29
 * Inventory delivery details for an item which can be fulfilled.
30
 */
31
class DetailItem implements IDetailItem
32
{
33
    use TPayload, TItem, TPhysicalAddress {
34
        TPhysicalAddress::getLines as getAddressLines;
35
        TPhysicalAddress::setLines as setAddressLines;
36
        TPhysicalAddress::getCity as getAddressCity;
37
        TPhysicalAddress::setCity as setAddressCity;
38
        TPhysicalAddress::getMainDivision as getAddressMainDivision;
39
        TPhysicalAddress::setMainDivision as setAddressMainDivision;
40
        TPhysicalAddress::getCountryCode as getAddressCountryCode;
41
        TPhysicalAddress::setCountryCode as setAddressCountryCode;
42
        TPhysicalAddress::getPostalCode as getAddressPostalCode;
43
        TPhysicalAddress::setPostalCode as setAddressPostalCode;
44
    }
45
46
    const ROOT_NODE = 'InventoryDetail';
47
    const SHIP_FROM_ADDRESS = 'ShipFromAddress';
48
49
    /** @var DateTime */
50
    protected $deliveryWindowFromDate;
51
    /** @var DateTime */
52
    protected $deliveryWindowToDate;
53
    /** @var DateTime */
54
    protected $shippingWindowFromDate;
55
    /** @var DateTime */
56
    protected $shippingWindowToDate;
57
    /** @var DateTime */
58
    protected $deliveryEstimateCreationTime;
59
    /** @var DateTime */
60
    protected $deliveryEstimateDisplayFlag;
61
    /** @var string */
62
    protected $deliveryEstimateMessage;
63
64
    /**
65
     * @param IValidatorIterator
66
     * @param ISchemaValidator
67
     * @param IPayloadMap
68
     * @param LoggerInterface
69
     * @param IPayload
70
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
71
     */
72
    public function __construct(
73
        IValidatorIterator $validators,
74
        ISchemaValidator $schemaValidator,
75
        IPayloadMap $payloadMap,
76
        LoggerInterface $logger,
77
        IPayload $parentPayload = null
78
    ) {
79
        $this->logger = $logger;
0 ignored issues
show
Documentation Bug introduced by
It seems like $logger of type object<Psr\Log\LoggerInterface> is incompatible with the declared type object<eBayEnterprise\Re...ayload\LoggerInterface> of property $logger.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
80
        $this->validators = $validators;
81
        $this->schemaValidator = $schemaValidator;
82
        $this->payloadMap = $payloadMap;
83
        $this->parentPayload = $parentPayload;
84
        $this->payloadFactory = new PayloadFactory;
85
86
        $this->extractionPaths = [
87
            'itemId' => 'string(@itemId)',
88
            'id' => 'string(@lineId)',
89
            'deliveryWindowFromDate' => 'string(x:DeliveryEstimate/x:DeliveryWindow/x:From)',
90
            'deliveryWindowToDate' => 'string(x:DeliveryEstimate/x:DeliveryWindow/x:To)',
91
            'shippingWindowFromDate' => 'string(x:DeliveryEstimate/x:ShippingWindow/x:From)',
92
            'shippingWindowToDate' => 'string(x:DeliveryEstimate/x:ShippingWindow/x:To)',
93
            'deliveryEstimateCreationTime' => 'string(x:DeliveryEstimate/x:CreationTime)',
94
            'deliveryEstimateDisplayFlag' => 'string(x:DeliveryEstimate/x:Display)',
95
            'city' => 'string(x:ShipFromAddress/x:City)',
96
            'countryCode' => 'string(x:ShipFromAddress/x:CountryCode)',
97
        ];
98
        $this->optionalExtractionPaths = [
99
            'deliveryEstimateMessage' => 'x:DeliveryEstimate/x:Message',
100
            'mainDivision' => 'x:ShipFromAddress/x:MainDivision',
101
            'postalCode' => 'x:ShipFromAddress/x:PostalCode',
102
        ];
103
        $this->addressLinesExtractionMap = [
104
            [
105
                'property' => 'lines',
106
                'xPath' => 'x:ShipFromAddress/*[starts-with(name(), "Line")]'
107
            ],
108
        ];
109
    }
110
111
    /**
112
     * The earliest date when the order line item is expected to arrive at the ship-to address.
113
     *
114
     * @return DateTime
115
     */
116
    public function getDeliveryWindowFromDate()
117
    {
118
        return $this->deliveryWindowFromDate;
119
    }
120
121
    /**
122
     * @param DateTime
123
     * @return self
124
     */
125
    public function setDeliveryWindowFromDate(DateTime $deliveryWindowFromDate)
126
    {
127
        $this->deliveryWindowFromDate = $deliveryWindowFromDate;
128
        return $this;
129
    }
130
131
    /**
132
     * The latest date when the order line item is expected to arrive at the ship-to address.
133
     *
134
     * @return DateTime
135
     */
136
    public function getDeliveryWindowToDate()
137
    {
138
        return $this->deliveryWindowToDate;
139
    }
140
141
    /**
142
     * @param DateTime
143
     * @return self
144
     */
145
    public function setDeliveryWindowToDate(DateTime $deliveryWindowToDate)
146
    {
147
        $this->deliveryWindowToDate = $deliveryWindowToDate;
148
        return $this;
149
    }
150
151
    /**
152
     * The earliest date when the order line item is expected to leave the fulfillment node.
153
     *
154
     * @return DateTime
155
     */
156
    public function getShippingWindowFromDate()
157
    {
158
        return $this->shippingWindowFromDate;
159
    }
160
161
    /**
162
     * @param DateTime
163
     * @return self
164
     */
165
    public function setShippingWindowFromDate(DateTime $shippingWindowFromDate)
166
    {
167
        $this->shippingWindowFromDate = $shippingWindowFromDate;
168
        return $this;
169
    }
170
171
    /**
172
     * The latest date when the order line item is expected to leave the fulfillment node.
173
     *
174
     * @return DateTime
175
     */
176
    public function getShippingWindowToDate()
177
    {
178
        return $this->shippingWindowToDate;
179
    }
180
181
    /**
182
     * @param DateTime
183
     * @return self
184
     */
185
    public function setShippingWindowToDate(DateTime $shippingWindowToDate)
186
    {
187
        $this->shippingWindowToDate = $shippingWindowToDate;
188
        return $this;
189
    }
190
191
    /**
192
     * The date-time when this delivery estimate was created
193
     *
194
     * @return DateTime
195
     */
196
    public function getDeliveryEstimateCreationTime()
197
    {
198
        return $this->deliveryEstimateCreationTime;
199
    }
200
201
    /**
202
     * @param DateTime
203
     * @return self
204
     */
205
    public function setDeliveryEstimateCreationTime(DateTime $deliveryEstimateCreationTime)
206
    {
207
        $this->deliveryEstimateCreationTime = $deliveryEstimateCreationTime;
208
        return $this;
209
    }
210
211
    /**
212
     * Indicates if the delivery estimate should be displayed.
213
     *
214
     * @return DateTime
215
     */
216
    public function getDeliveryEstimateDisplayFlag()
217
    {
218
        return $this->deliveryEstimateDisplayFlag;
219
    }
220
221
    /**
222
     * @param DateTime
223
     * @return self
224
     */
225
    public function setDeliveryEstimateDisplayFlag(DateTime $deliveryEstimateDisplayFlag)
226
    {
227
        $this->deliveryEstimateDisplayFlag = $deliveryEstimateDisplayFlag;
228
        return $this;
229
    }
230
231
    /**
232
     * not currently used.
233
     *
234
     * restrictions: optional
235
     * @return string
236
     */
237
    public function getDeliveryEstimateMessage()
238
    {
239
        return $this->deliveryEstimateMessage;
240
    }
241
242
    /**
243
     * @param string
244
     * @return self
245
     */
246
    public function setDeliveryEstimateMessage($deliveryEstimateMessage)
247
    {
248
        $this->deliveryEstimateMessage = $deliveryEstimateMessage;
249
        return $this;
250
    }
251
252
    protected function serializeContents()
253
    {
254
        return $this->serializeDeliveryEstimate()
255
            . $this->serializePhysicalAddress();
256
    }
257
258
    protected function serializeDeliveryEstimate()
259
    {
260
        return '<DeliveryEstimate>'
261
            . '<DeliveryWindow>'
262
            . $this->serializeDateTime('From', $this->getDeliveryWindowFromDate())
263
            . $this->serializeDateTime('To', $this->getDeliveryWindowToDate())
264
            . '</DeliveryWindow>'
265
            . '<ShippingWindow>'
266
            . $this->serializeDateTime('From', $this->getShippingWindowFromDate())
267
            . $this->serializeDateTime('To', $this->getShippingWindowToDate())
268
            . '</ShippingWindow>'
269
            . $this->serializeDateTime('CreationTime', $this->getDeliveryEstimateCreationTime())
270
            . "<Display>{$this->convertBooleanToString($this->getDeliveryEstimateDisplayFlag())}</Display>"
271
            . $this->serializeOptionalValue('Message', $this->getDeliveryEstimateMessage())
272
            . '</DeliveryEstimate>';
273
    }
274
275
    protected function serializeDateTime($nodeName, $dateTime)
276
    {
277
        return is_null($dateTime) ? "<{$nodeName}/>" :
278
            "<{$nodeName}>{$dateTime->format('c')}</{$nodeName}>";
279
    }
280
281
    protected function deserializeExtra()
282
    {
283
        $dateFields = [
284
            'deliveryWindowFromDate',
285
            'deliveryWindowToDate',
286
            'shippingWindowFromDate',
287
            'shippingWindowToDate',
288
            'deliveryEstimateCreationTime',
289
        ];
290
        foreach ($dateFields as $property) {
291
            $dateTime = $this->$property ? new DateTime($this->$property) : null;
292
            // ensure the property is set to null if the datetime creation fails
293
            $this->$property = $dateTime ?: null;
294
        }
295
        $this->deliveryEstimateDisplayFlag = $this->convertStringToBoolean($this->deliveryEstimateDisplayFlag);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->convertStringToBo...eryEstimateDisplayFlag) can also be of type boolean. However, the property $deliveryEstimateDisplayFlag is declared as type object<DateTime>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
296
    }
297
298
    protected function getPhysicalAddressRootNodeName()
299
    {
300
        return static::SHIP_FROM_ADDRESS;
301
    }
302
303
    protected function getRootAttributes()
304
    {
305
        return [
306
            'itemId' => $this->getItemId(),
307
            'lineId' => $this->getId(),
308
        ];
309
    }
310
311
    protected function getRootNodeName()
312
    {
313
        return static::ROOT_NODE;
314
    }
315
316
    protected function getXmlNamespace()
317
    {
318
        return static::XML_NS;
319
    }
320
}
321