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.

OrderSummary::setChainedOrder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 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-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\Customer;
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 Psr\Log\LoggerInterface;
24
use Psr\Log\NullLogger;
25
use DateTime;
26
27
class OrderSummary implements IOrderSummary
28
{
29
    use TPayload;
30
31
    /** @var string */
32
    protected $id;
33
    /** @var string */
34
    protected $orderType;
35
    /** @var string */
36
    protected $orderPurpose;
37
    /** @var string */
38
    protected $testType;
39
    /** @var DateTime */
40
    protected $modifiedTime;
41
    /** @var string */
42
    protected $cancellable;
43
    /** @var string */
44
    protected $customerOrderId;
45
    /** @var string */
46
    protected $customerId;
47
    /** @var DateTime */
48
    protected $orderDate;
49
    /** @var string */
50
    protected $dashboardRepId;
51
    /** @var string */
52
    protected $status;
53
    /** @var string */
54
    protected $orderTotal;
55
    /** @var string */
56
    protected $source;
57
    /** @var string */
58
    protected $chainedOrder;
59
    /** @var string */
60
    protected $type;
61
    /** @var string */
62
    protected $parentRef;
63
    /** @var string */
64
    protected $derivedOrder;
65
66
    /**
67
     * @param IValidatorIterator
68
     * @param ISchemaValidator
69
     * @param IPayloadMap
70
     * @param LoggerInterface
71
     * @param IPayload
72
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
73
     */
74
    public function __construct(
75
        IValidatorIterator $validators,
76
        ISchemaValidator $schemaValidator,
77
        IPayloadMap $payloadMap,
0 ignored issues
show
Unused Code introduced by
The parameter $payloadMap is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
        LoggerInterface $logger,
79
        IPayload $parentPayload = null
80
    ) {
81
        $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...
82
        $this->validators = $validators;
83
        $this->schemaValidator = $schemaValidator;
84
        $this->parentPayload = $parentPayload;
85
86
        $this->extractionPaths = [
87
            'id' => 'string(@id)',
88
            'orderTotal' => 'string(x:OrderTotal)',
89
        ];
90
        $this->optionalExtractionPaths = [
91
            'orderType' => '@orderType',
92
            'orderPurpose' => '@orderPurpose',
93
            'testType' => '@testType',
94
            'cancellable' => '@cancellable',
95
            'customerOrderId' => 'x:CustomerOrderId',
96
            'customerId' => 'x:CustomerId',
97
            'dashboardRepId' => 'x:DashboardRepId',
98
            'status' => 'x:Status',
99
            'source' => 'x:Source',
100
            'chainedOrder' => 'x:ChainedOrder',
101
            'type' => 'x:ChainedOrder/@type',
102
            'parentRef' => 'x:ChainedOrder/@parentRef|x:DerivedOrder/@parentRef',
103
            'derivedOrder' => 'x:DerivedOrder',
104
        ];
105
        $this->datetimeExtractionPaths = [
106
            'modifiedTime' => 'string(@modifiedTime)',
107
            'orderDate' => 'string(x:OrderDate)',
108
        ];
109
    }
110
111
    /**
112
     * @see IOrderSummary::getId()
113
     */
114
    public function getId()
115
    {
116
        return $this->id;
117
    }
118
119
    /**
120
     * @see IOrderSummary::setId()
121
     * @codeCoverageIgnore
122
     */
123
    public function setId($id)
124
    {
125
        $this->id = $id;
126
        return $this;
127
    }
128
129
    /**
130
     * @see IOrderSummary::getOrderType()
131
     */
132
    public function getOrderType()
133
    {
134
        return $this->orderType;
135
    }
136
137
    /**
138
     * @see IOrderSummary::setOrderType()
139
     * @codeCoverageIgnore
140
     */
141
    public function setOrderType($orderType)
142
    {
143
        $this->orderType = $orderType;
144
        return $this;
145
    }
146
147
    /**
148
     * @see IOrderSummary::getOrderPurpose()
149
     */
150
    public function getOrderPurpose()
151
    {
152
        return $this->orderPurpose;
153
    }
154
155
    /**
156
     * @see IOrderSummary::setOrderPurpose()
157
     * @codeCoverageIgnore
158
     */
159
    public function setOrderPurpose($orderPurpose)
160
    {
161
        $this->orderPurpose = $orderPurpose;
162
        return $this;
163
    }
164
165
   /**
166
     * @see IOrderSummary::getTestType()
167
     */
168
    public function getTestType()
169
    {
170
        return $this->testType;
171
    }
172
173
   /**
174
     * @see IOrderSummary::setTestType()
175
     * @codeCoverageIgnore
176
     */
177
    public function setTestType($testType)
178
    {
179
        $this->testType = $testType;
180
        return $this;
181
    }
182
183
   /**
184
     * @see IOrderSummary::getModifiedTime()
185
     */
186
    public function getModifiedTime()
187
    {
188
        return $this->modifiedTime;
189
    }
190
191
   /**
192
     * @see IOrderSummary::setModifiedTime()
193
     * @codeCoverageIgnore
194
     */
195
    public function setModifiedTime(DateTime $modifiedTime)
196
    {
197
        $this->modifiedTime = $modifiedTime;
198
        return $this;
199
    }
200
201
    /**
202
     * @see IOrderSummary::getCancellable()
203
     */
204
    public function getCancellable()
205
    {
206
        return $this->cancellable;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->cancellable; (string) is incompatible with the return type declared by the interface eBayEnterprise\RetailOrd...Summary::getCancellable of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
207
    }
208
209
    /**
210
     * @see IOrderSummary::setCancellable()
211
     * @codeCoverageIgnore
212
     */
213
    public function setCancellable($cancellable)
214
    {
215
        $this->cancellable = $cancellable;
216
        return $this;
217
    }
218
219
    /**
220
     * @see IOrderSummary::getCustomerId()
221
     */
222
    public function getCustomerId()
223
    {
224
        return $this->customerId;
225
    }
226
227
     /**
228
     * @see IOrderSummary::setCustomerId()
229
     * @codeCoverageIgnore
230
     */
231
    public function setCustomerId($customerId)
232
    {
233
        $this->customerId = $customerId;
234
        return $this;
235
    }
236
237
   /**
238
     * @see IOrderSummary::getCustomerOrderId()
239
     */
240
    public function getCustomerOrderId()
241
    {
242
        return $this->customerOrderId;
243
    }
244
245
    /**
246
     * @see IOrderSummary::setCustomerOrderId()
247
     * @codeCoverageIgnore
248
     */
249
    public function setCustomerOrderId($customerOrderId)
250
    {
251
        $this->customerOrderId = $customerOrderId;
252
        return $this;
253
    }
254
255
    /**
256
     * @see IOrderSummary::getOrderDate()
257
     */
258
    public function getOrderDate()
259
    {
260
        return $this->orderDate;
261
    }
262
263
    /**
264
     * @see IOrderSummary::setOrderDate()
265
     * @codeCoverageIgnore
266
     */
267
    public function setOrderDate(DateTime $orderDate)
268
    {
269
        $this->orderDate = $orderDate;
270
        return $this;
271
    }
272
273
    /**
274
     * @see IOrderSummary::getDashboardRepId()
275
     */
276
    public function getDashboardRepId()
277
    {
278
        return $this->dashboardRepId;
279
    }
280
281
    /**
282
     * @see IOrderSummary::setDashboardRepId()
283
     * @codeCoverageIgnore
284
     */
285
    public function setDashboardRepId($dashboardRepId)
286
    {
287
        $this->dashboardRepId = $dashboardRepId;
288
        return $this;
289
    }
290
291
    /**
292
     * @see IOrderSummary::getStatus()
293
     */
294
    public function getStatus()
295
    {
296
        return $this->status;
297
    }
298
299
   /**
300
     * @see IOrderSummary::setStatus()
301
     * @codeCoverageIgnore
302
     */
303
    public function setStatus($status)
304
    {
305
        $this->status = $status;
306
        return $this;
307
    }
308
309
    /**
310
     * @see IOrderSummary::getOrderTotal()
311
     */
312
    public function getOrderTotal()
313
    {
314
        return $this->orderTotal;
315
    }
316
317
   /**
318
     * @see IOrderSummary::setOrderTotal()
319
     * @codeCoverageIgnore
320
     */
321
    public function setOrderTotal($orderTotal)
322
    {
323
        $this->orderTotal = $orderTotal;
324
        return $this;
325
    }
326
327
    /**
328
     * @see IOrderSummary::getSource()
329
     */
330
    public function getSource()
331
    {
332
        return $this->source;
333
    }
334
335
   /**
336
     * @see IOrderSummary::setSource()
337
     * @codeCoverageIgnore
338
     */
339
    public function setSource($source)
340
    {
341
        $this->source = $source;
342
        return $this;
343
    }
344
345
    /**
346
     * @see IOrderSummary::getChainedOrder()
347
     */
348
    public function getChainedOrder()
349
    {
350
        return $this->chainedOrder;
351
    }
352
353
    /**
354
     * @see IOrderSummary::setChainedOrder()
355
     * @codeCoverageIgnore
356
     */
357
    public function setChainedOrder($chainedOrder)
358
    {
359
        $this->chainedOrder = $chainedOrder;
360
        return $this;
361
    }
362
363
   /**
364
     * @see IOrderSummary::getType()
365
     */
366
    public function getType()
367
    {
368
        return $this->type;
369
    }
370
371
    /**
372
     * @see IOrderSummary::setType()
373
     * @codeCoverageIgnore
374
     */
375
    public function setType($type)
376
    {
377
        $this->type = $type;
378
        return $this;
379
    }
380
381
    /**
382
     * @see IOrderSummary::getParentRef()
383
     */
384
    public function getParentRef()
385
    {
386
        return $this->parentRef;
387
    }
388
389
    /**
390
     * @see IOrderSummary::setParentRef()
391
     * @codeCoverageIgnore
392
     */
393
    public function setParentRef($parentRef)
394
    {
395
        $this->parentRef = $parentRef;
396
        return $this;
397
    }
398
399
    /**
400
     * @see IOrderSummary::getDerivedOrder()
401
     */
402
    public function getDerivedOrder()
403
    {
404
        return $this->derivedOrder;
405
    }
406
407
    /**
408
     * @see IOrderSummary::setDerivedOrder()
409
     * @codeCoverageIgnore
410
     */
411
    public function setDerivedOrder($derivedOrder)
412
    {
413
        $this->derivedOrder = $derivedOrder;
414
        return $this;
415
    }
416
417
    /**
418
     * @see TPayload::serializeContents()
419
     */
420
    protected function serializeContents()
421
    {
422
        return $this->serializeOptionalXmlEncodedValue('CustomerOrderId', $this->getCustomerOrderId())
423
            . $this->serializeOptionalXmlEncodedValue('CustomerId', $this->getCustomerId())
424
            . $this->serializeOptionalDateValue('OrderDate', 'c', $this->getOrderDate())
425
            . $this->serializeOptionalXmlEncodedValue('DashboardRepId', $this->getDashboardRepId())
426
            . $this->serializeOptionalXmlEncodedValue('Status', $this->getStatus())
427
            . $this->serializeRequiredValue('OrderTotal', $this->xmlEncode($this->getOrderTotal()))
428
            . $this->serializeOptionalXmlEncodedValue('Source', $this->getSource())
429
            . $this->serializeChainedOrder('ChainedOrder', $this->xmlEncode($this->getChainedOrder()))
430
            . $this->serializeDerivedOrder('DerivedOrder', $this->xmlEncode($this->getDerivedOrder()));
431
    }
432
433
    /**
434
     * Serialize the chain order node.
435
     * @return string | null
436
     */
437 View Code Duplication
    protected function serializeChainedOrder($node, $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...
438
    {
439
        $parentRef = $this->getParentRef();
440
        $typeAttribute = $this->serializeOptionalAttribute('type', $this->xmlEncode($this->getType()));
441
        $parentRefAttribute = $this->serializeOptionalAttribute('parentRef', $this->xmlEncode($parentRef));
442
        return $parentRef
443
            ? sprintf('<%s %s %s>%s</%1$s>', $node, $typeAttribute, $parentRefAttribute, $value) : null;
444
    }
445
446
    /**
447
     * Serialize the derived order node.
448
     * @return string | null
449
     */
450
    protected function serializeDerivedOrder($node, $value)
451
    {
452
        $parentRef = $this->getParentRef();
453
        $parentRefAttribute = $this->serializeOptionalAttribute('parentRef', $this->xmlEncode($parentRef));
454
        return $parentRef
455
            ? sprintf('<%s %s>%s</%1$s>', $node, $parentRefAttribute, $value) : null;
456
    }
457
458
    /**
459
     * @see TPayload::getRootNodeName()
460
     */
461
    protected function getRootNodeName()
462
    {
463
        return static::ROOT_NODE;
464
    }
465
466
    /**
467
     * @see TPayload::getXmlNamespace()
468
     */
469
    protected function getXmlNamespace()
470
    {
471
        return self::XML_NS;
472
    }
473
474
    /**
475
     * @see TPayload::getRootAttributes()
476
     */
477
    protected function getRootAttributes()
478
    {
479
        $orderType = $this->getOrderType();
480
        $orderPurpose = $this->getOrderPurpose();
481
        $testType = $this->getTestType();
482
        $cancellable = $this->getCancellable();
483
        return array_merge(
484
            ['id' => $this->getId()],
485
            $orderType ? ['orderType' => $orderType] : [],
486
            $orderPurpose ? ['orderPurpose' => $orderPurpose] : [],
487
            $testType ? ['testType' => $testType] : [],
488
            ['modifiedTime' => $this->getModifiedTime()->format('c')],
489
            $cancellable ? ['cancellable' => $cancellable] : []
490
        );
491
    }
492
}
493