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.

Shipment   A
last analyzed

Complexity

Total Complexity 28

Size/Duplication

Total Lines 322
Duplicated Lines 2.17 %

Coupling/Cohesion

Components 6
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 28
c 2
b 0
f 0
lcom 6
cbo 2
dl 7
loc 322
rs 9.0909

27 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A getDestinationRef() 0 4 1
A getWarehouse() 0 4 1
A getCarrier() 0 4 1
A getMode() 0 4 1
A getDisplayText() 0 4 1
A getTotalWeight() 0 4 1
A getShippedDate() 0 4 1
A getRootNodeName() 0 4 1
A getXmlNamespace() 0 4 1
A __construct() 0 20 1
A initExtractPaths() 0 10 1
A initOptionalExtractPaths() 0 9 1
A initSubPayloadExtractPaths() 0 7 1
A initDatetimeExtractPaths() 0 7 1
A initSubPayloadProperties() 0 7 1
A setId() 0 5 1
A setDestinationRef() 0 5 1
A setWarehouse() 0 5 1
A setCarrier() 0 5 1
A setMode() 0 5 1
A setDisplayText() 0 5 1
A setTotalWeight() 0 5 1
A setShippedDate() 0 5 1
A serializeContents() 0 8 1
A serializeCarrierValue() 7 7 2
A getRootAttributes() 0 7 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
 * 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-2015 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\Order\Detail;
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\TPayload;
23
use eBayEnterprise\RetailOrderManagement\Payload\PayloadFactory;
24
use Psr\Log\LoggerInterface;
25
use Psr\Log\NullLogger;
26
use DateTime;
27
28
class Shipment implements IShipment
29
{
30
    use TPayload, TShippedItemContainer;
31
32
    /** @var string */
33
    protected $id;
34
    /** @var string */
35
    protected $destinationRef;
36
    /** @var string */
37
    protected $warehouse;
38
    /** @var string */
39
    protected $carrier;
40
    /** @var string */
41
    protected $mode;
42
    /** @var string */
43
    protected $displayText;
44
    /** @var string */
45
    protected $totalWeight;
46
    /** @var DateTime */
47
    protected $shippedDate;
48
49
    /**
50
     * @param IValidatorIterator
51
     * @param ISchemaValidator
52
     * @param IPayloadMap
53
     * @param LoggerInterface
54
     * @param IPayload
55
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
56
     */
57
    public function __construct(
58
        IValidatorIterator $validators,
59
        ISchemaValidator $schemaValidator,
60
        IPayloadMap $payloadMap,
61
        LoggerInterface $logger,
62
        IPayload $parentPayload = null
63
    ) {
64
        $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...
65
        $this->validators = $validators;
66
        $this->schemaValidator = $schemaValidator;
67
        $this->parentPayload = $parentPayload;
68
        $this->payloadMap = $payloadMap;
69
        $this->payloadFactory = $this->getNewPayloadFactory();
70
71
        $this->initExtractPaths()
72
            ->initOptionalExtractPaths()
73
            ->initDatetimeExtractPaths()
74
            ->initSubPayloadExtractPaths()
75
            ->initSubPayloadProperties();
76
    }
77
78
    /**
79
     * Initialize the protected class property array self::extractionPaths with xpath
80
     * key/value pairs.
81
     *
82
     * @return self
83
     */
84
    protected function initExtractPaths()
85
    {
86
        $this->extractionPaths = [
87
            'id' => 'string(@id)',
88
            'destinationRef' => 'string(@destinationRef)',
89
            'warehouse' => 'string(x:Warehouse)',
90
            'totalWeight' => 'string(x:TotalWeight)',
91
        ];
92
        return $this;
93
    }
94
95
    /**
96
     * Initialize the protected class property array self::optionalExtractionPaths with xpath
97
     * key/value pairs.
98
     *
99
     * @return self
100
     */
101
    protected function initOptionalExtractPaths()
102
    {
103
        $this->optionalExtractionPaths = [
104
            'carrier' => 'x:Carrier',
105
            'mode' => 'x:Carrier/@mode',
106
            'displayText' => 'x:Carrier/@displayText',
107
        ];
108
        return $this;
109
    }
110
111
    /**
112
     * Initialize the protected class property array self::subpayloadExtractionPaths with xpath
113
     * key/value pairs.
114
     *
115
     * @return self
116
     */
117
    protected function initSubPayloadExtractPaths()
118
    {
119
        $this->subpayloadExtractionPaths = [
120
            'shippedItems' => 'x:ShippedItems',
121
        ];
122
        return $this;
123
    }
124
125
    /**
126
     * Initialize the protected class property array self::datetimeExtractionPaths with xpath
127
     * key/value pairs.
128
     *
129
     * @return self
130
     */
131
    protected function initDatetimeExtractPaths()
132
    {
133
        $this->datetimeExtractionPaths = [
134
            'shippedDate' => 'string(x:ShippedDate)',
135
        ];
136
        return $this;
137
    }
138
139
    /**
140
     * Initialize any sub-payload class properties with their concrete instance.
141
     *
142
     * @return self
143
     */
144
    protected function initSubPayloadProperties()
145
    {
146
        $this->setShippedItems($this->buildPayloadForInterface(
0 ignored issues
show
Compatibility introduced by
$this->buildPayloadForIn...TEM_ITERABLE_INTERFACE) of type object<eBayEnterprise\Re...ement\Payload\IPayload> is not a sub-type of object<eBayEnterprise\Re...l\IShippedItemIterable>. It seems like you assume a child interface of the interface eBayEnterprise\RetailOrd...gement\Payload\IPayload to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
147
            static::SHIPPED_ITEM_ITERABLE_INTERFACE
148
        ));
149
        return $this;
150
    }
151
152
    /**
153
     * @see IShipment::getId()
154
     */
155
    public function getId()
156
    {
157
        return $this->id;
158
    }
159
160
    /**
161
     * @see IShipment::setId()
162
     * @codeCoverageIgnore
163
     */
164
    public function setId($id)
165
    {
166
        $this->id = $id;
167
        return $this;
168
    }
169
170
    /**
171
     * @see IShipment::getDestinationRef()
172
     */
173
    public function getDestinationRef()
174
    {
175
        return $this->destinationRef;
176
    }
177
178
    /**
179
     * @see IShipment::setDestinationRef()
180
     * @codeCoverageIgnore
181
     */
182
    public function setDestinationRef($destinationRef)
183
    {
184
        $this->destinationRef = $destinationRef;
185
        return $this;
186
    }
187
188
    /**
189
     * @see IShipment::getWarehouse()
190
     */
191
    public function getWarehouse()
192
    {
193
        return $this->warehouse;
194
    }
195
196
    /**
197
     * @see IShipment::setWarehouse()
198
     * @codeCoverageIgnore
199
     */
200
    public function setWarehouse($warehouse)
201
    {
202
        $this->warehouse = $warehouse;
203
        return $this;
204
    }
205
206
    /**
207
     * @see IShipment::getCarrier()
208
     */
209
    public function getCarrier()
210
    {
211
        return $this->carrier;
212
    }
213
214
    /**
215
     * @see IShipment::setCarrier()
216
     * @codeCoverageIgnore
217
     */
218
    public function setCarrier($carrier)
219
    {
220
        $this->carrier = $carrier;
221
        return $this;
222
    }
223
224
    /**
225
     * @see IShipment::getMode()
226
     */
227
    public function getMode()
228
    {
229
        return $this->mode;
230
    }
231
232
    /**
233
     * @see IShipment::setMode()
234
     * @codeCoverageIgnore
235
     */
236
    public function setMode($mode)
237
    {
238
        $this->mode = $mode;
239
        return $this;
240
    }
241
242
    /**
243
     * @see IShipment::getDisplayText()
244
     */
245
    public function getDisplayText()
246
    {
247
        return $this->displayText;
248
    }
249
250
    /**
251
     * @see IShipment::setDisplayText()
252
     * @codeCoverageIgnore
253
     */
254
    public function setDisplayText($displayText)
255
    {
256
        $this->displayText = $displayText;
257
        return $this;
258
    }
259
260
    /**
261
     * @see IShipment::getTotalWeight()
262
     */
263
    public function getTotalWeight()
264
    {
265
        return $this->totalWeight;
266
    }
267
268
    /**
269
     * @see IShipment::setTotalWeight()
270
     * @codeCoverageIgnore
271
     */
272
    public function setTotalWeight($totalWeight)
273
    {
274
        $this->totalWeight = $totalWeight;
275
        return $this;
276
    }
277
278
    /**
279
     * @see IShipment::getShippedDate()
280
     */
281
    public function getShippedDate()
282
    {
283
        return $this->shippedDate;
284
    }
285
286
    /**
287
     * @see IShipment::setShippedDate()
288
     * @codeCoverageIgnore
289
     */
290
    public function setShippedDate(DateTime $shippedDate)
291
    {
292
        $this->shippedDate = $shippedDate;
293
        return $this;
294
    }
295
296
    /**
297
     * @see TPayload::serializeContents()
298
     */
299
    protected function serializeContents()
300
    {
301
        return $this->getShippedItems()->serialize()
302
            . $this->serializeRequiredValue('Warehouse', $this->xmlEncode($this->getWarehouse()))
303
            . $this->serializeCarrierValue('Carrier', $this->getCarrier())
304
            . $this->serializeRequiredValue('TotalWeight', $this->xmlEncode($this->getTotalWeight()))
305
            . $this->serializeOptionalDateValue('ShippedDate', 'c', $this->getShippedDate());
306
    }
307
308
    /**
309
     * @see TPayload::getRootNodeName()
310
     */
311
    protected function getRootNodeName()
312
    {
313
        return static::ROOT_NODE;
314
    }
315
316
    /**
317
     * @see TPayload::getXmlNamespace()
318
     */
319
    protected function getXmlNamespace()
320
    {
321
        return self::XML_NS;
322
    }
323
324
    /**
325
     * Serializing the carrier XML node.
326
     *
327
     * @param  string
328
     * @param  string
329
     * @return string | null
330
     */
331 View Code Duplication
    protected function serializeCarrierValue($nodeName, $value)
0 ignored issues
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...
332
    {
333
        $modeAttribute = $this->serializeOptionalAttribute('mode', $this->xmlEncode($this->getMode()));
334
        $displayTextAttribute = $this->serializeOptionalAttribute('displayText', $this->xmlEncode($this->getDisplayText()));
335
        return $value
336
            ? sprintf('<%s %s %s>%s</%1$s>', $nodeName, $modeAttribute, $displayTextAttribute, $this->xmlEncode($value)) : null;
337
    }
338
339
   /**
340
     * @see TPayload::getRootAttributes()
341
     */
342
    protected function getRootAttributes()
343
    {
344
        return [
345
            'id' => $this->getId(),
346
            'destinationRef' => $this->getDestinationRef(),
347
        ];
348
    }
349
}
350