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.

OrderDetailResponse::setOrder()   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\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\TTopLevelPayload;
23
use eBayEnterprise\RetailOrderManagement\Payload\PayloadFactory;
24
use Psr\Log\LoggerInterface;
25
use Psr\Log\NullLogger;
26
27
class OrderDetailResponse implements IOrderDetailResponse
28
{
29
    use TTopLevelPayload;
30
31
    /** @var string */
32
    protected $orderType;
33
    /** @var string */
34
    protected $testType;
35
    /** @var string */
36
    protected $cancellable;
37
    /** @var IOrderResponse */
38
    protected $order;
39
40
    /**
41
     * @param IValidatorIterator
42
     * @param ISchemaValidator
43
     * @param IPayloadMap
44
     * @param LoggerInterface
45
     * @param IPayload
46
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
47
     */
48
    public function __construct(
49
        IValidatorIterator $validators,
50
        ISchemaValidator $schemaValidator,
51
        IPayloadMap $payloadMap,
52
        LoggerInterface $logger,
53
        IPayload $parentPayload = null
54
    ) {
55
        $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...
56
        $this->validators = $validators;
57
        $this->schemaValidator = $schemaValidator;
58
        $this->parentPayload = $parentPayload;
59
        $this->payloadMap = $payloadMap;
60
        $this->payloadFactory = $this->getNewPayloadFactory();
61
62
        $this->initExtractPaths()
63
            ->initOptionalExtractPaths()
64
            ->initSubPayloadExtractPaths()
65
            ->initSubPayloadProperties();
66
    }
67
68
    /**
69
     * Initialize the protected class property array self::extractionPaths with xpath
70
     * key/value pairs.
71
     *
72
     * @return self
73
     */
74
    protected function initExtractPaths()
75
    {
76
        $this->extractionPaths = [
77
            'orderType' => 'string(@orderType)',
78
            'cancellable' => 'string(@cancellable)',
79
        ];
80
        return $this;
81
    }
82
83
    /**
84
     * Initialize the protected class property array self::optionalExtractionPaths with xpath
85
     * key/value pairs.
86
     *
87
     * @return self
88
     */
89
    protected function initOptionalExtractPaths()
90
    {
91
        $this->optionalExtractionPaths = [
92
            'testType' => '@testType',
93
        ];
94
        return $this;
95
    }
96
97
    /**
98
     * Initialize the protected class property array self::subpayloadExtractionPaths with xpath
99
     * key/value pairs.
100
     *
101
     * @return self
102
     */
103
    protected function initSubPayloadExtractPaths()
104
    {
105
        $this->subpayloadExtractionPaths = [
106
            'order' => 'x:Order',
107
        ];
108
        return $this;
109
    }
110
111
    /**
112
     * Initialize any sub-payload class properties with their concrete instance.
113
     *
114
     * @return self
115
     */
116
    protected function initSubPayloadProperties()
117
    {
118
        $this->setOrder($this->buildPayloadForInterface(
0 ignored issues
show
Compatibility introduced by
$this->buildPayloadForIn...DER_RESPONSE_INTERFACE) of type object<eBayEnterprise\Re...ement\Payload\IPayload> is not a sub-type of object<eBayEnterprise\Re...\Detail\IOrderResponse>. 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...
119
            static::ORDER_RESPONSE_INTERFACE
120
        ));
121
        return $this;
122
    }
123
124
    /**
125
     * @see IOrderDetailResponse::getOrderType()
126
     */
127
    public function getOrderType()
128
    {
129
        return $this->orderType;
130
    }
131
132
    /**
133
     * @see IOrderDetailResponse::setOrderType()
134
     * @codeCoverageIgnore
135
     */
136
    public function setOrderType($orderType)
137
    {
138
        $this->orderType = $orderType;
139
        return $this;
140
    }
141
142
    /**
143
     * @see IOrderDetailResponse::getTestType()
144
     */
145
    public function getTestType()
146
    {
147
        return $this->testType;
148
    }
149
150
   /**
151
     * @see IOrderDetailResponse::setTestType()
152
     * @codeCoverageIgnore
153
     */
154
    public function setTestType($testType)
155
    {
156
        $this->testType = $testType;
157
        return $this;
158
    }
159
160
    /**
161
     * @see IOrderDetailResponse::getCancellable()
162
     */
163
    public function getCancellable()
164
    {
165
        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...esponse::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...
166
    }
167
168
    /**
169
     * @see IOrderDetailResponse::setCancellable()
170
     * @codeCoverageIgnore
171
     */
172
    public function setCancellable($cancellable)
173
    {
174
        $this->cancellable = $cancellable;
175
        return $this;
176
    }
177
178
    /**
179
     * @see IOrderDetailResponse::getOrder()
180
     */
181
    public function getOrder()
182
    {
183
        return $this->order;
184
    }
185
186
    /**
187
     * @see IOrderDetailResponse::setOrder()
188
     * @codeCoverageIgnore
189
     */
190
    public function setOrder(IOrderResponse $order)
191
    {
192
        $this->order = $order;
193
        return $this;
194
    }
195
196
    /**
197
     * @see TPayload::serializeContents()
198
     */
199
    protected function serializeContents()
200
    {
201
        return $this->getOrder()->serialize();
202
    }
203
204
    /**
205
     * @see TPayload::getRootNodeName()
206
     */
207
    protected function getRootNodeName()
208
    {
209
        return static::ROOT_NODE;
210
    }
211
212
    /**
213
     * @see TPayload::getXmlNamespace()
214
     */
215
    protected function getXmlNamespace()
216
    {
217
        return self::XML_NS;
218
    }
219
220
    protected function getSchemaFile()
221
    {
222
        return $this->getSchemaDir() . self::XSD;
223
    }
224
225
    /**
226
     * Validate the serialized data via the schema validator.
227
     * @param  string
228
     * @return self
229
     */
230
    protected function schemaValidate($serializedData)
231
    {
232
        $this->schemaValidator->validate($serializedData, $this->getSchemaFile());
233
        return $this;
234
    }
235
236
    /**
237
     * @see TPayload::getRootAttributes()
238
     */
239
    protected function getRootAttributes()
240
    {
241
        $testType = $this->getTestType();
242
        return array_merge(
243
            ['xmlns' => $this->getXmlNamespace(), 'orderType' => $this->getOrderType()],
244
            $testType ? ['testType' => $testType] : [],
245
            ['cancellable' => $this->getCancellable()]
246
        );
247
    }
248
}
249