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.

ItemRelationship::__construct()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 29
rs 8.8571
cc 1
eloc 21
nc 1
nop 5
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;
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 Psr\Log\LoggerInterface;
25
use Psr\Log\NullLogger;
26
27
class ItemRelationship implements IItemRelationship
28
{
29
    use TPayload, TOrderItemReferenceContainer;
30
31
    const ROOT_NODE = 'Relationship';
32
33
    /** @var string */
34
    protected $parentItemId;
35
    /** @var IOrderItem */
36
    protected $parentItem;
37
    /** @var string */
38
    protected $type;
39
    /** @var string */
40
    protected $name;
41
    /** @var array */
42
    protected $allowedRelationshipTypes = [
43
        self::TYPE_BUNDLE,
44
        self::TYPE_WARRANTY,
45
        self::TYPE_KIT,
46
        self::TYPE_DYNAMIC,
47
        self::TYPE_CUSTOMIZATION,
48
    ];
49
50
    /**
51
     * @param IValidatorIterator
52
     * @param ISchemaValidator
53
     * @param IPayloadMap
54
     * @param LoggerInterface
55
     * @param IPayload
56
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
57
     */
58
    public function __construct(
59
        IValidatorIterator $validators,
60
        ISchemaValidator $schemaValidator,
61
        IPayloadMap $payloadMap,
62
        LoggerInterface $logger,
63
        IPayload $parentPayload = null
64
    ) {
65
        $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...
66
        $this->validators = $validators;
67
        $this->schemaValidator = $schemaValidator;
68
        $this->payloadMap = $payloadMap;
69
        $this->parentPayload = $parentPayload;
70
        $this->payloadFactory = new PayloadFactory;
71
72
        $this->extractionPaths = [
73
            'parentItemId' => 'string(@parent)',
74
            'type' => 'string(x:Type)',
75
        ];
76
        $this->optionalExtractionPaths = [
77
            'name' => 'x:Name',
78
        ];
79
        $this->subpayloadExtractionPaths = [
80
            'itemReferences' => 'x:Members',
81
        ];
82
83
        $this->itemReferences = $this->buildPayloadForInterface(
84
            self::ITEM_REFERENCE_ITERABLE_INTERFACE
85
        );
86
    }
87
88 View Code Duplication
    public function getParentItem()
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...
89
    {
90
        if (!$this->parentItem && $this->parentItemId) {
91
            $itemContainer = $this->getItemContainer();
92
            if ($itemContainer) {
93
                foreach ($itemContainer->getOrderItems() as $item) {
94
                    if ($item->getId() === $this->parentItemId) {
95
                        $this->parentItem = $item;
96
                        break;
97
                    }
98
                }
99
            }
100
        }
101
        return $this->parentItem;
102
    }
103
104 View Code Duplication
    public function setParentItem(IOrderItem $parentItem)
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...
105
    {
106
        $this->parentItem = $parentItem;
107
        $itemContainer = $this->getItemContainer();
108
        if ($itemContainer) {
109
            $itemContainer->getOrderItems()->offsetSet($parentItem);
110
        }
111
        return $this;
112
    }
113
114
    public function getParentItemId()
115
    {
116
        $item = $this->getParentItem();
117
        return $item ? $item->getId() : $this->parentItemId;
118
    }
119
120
    public function getType()
121
    {
122
        return $this->type;
123
    }
124
125
    public function setType($type)
126
    {
127
        $this->type = in_array($type, $this->allowedRelationshipTypes) ? $type : null;
128
        return $this;
129
    }
130
131
    public function getName()
132
    {
133
        return $this->name;
134
    }
135
136
    public function setName($name)
137
    {
138
        $this->name = $name;
139
        return $this;
140
    }
141
142
    /**
143
     * Get the order item container associated with this payload. Will return
144
     * null if one cannot be found.
145
     *
146
     * @return IOrderItemContainer|null
147
     */
148
    protected function getItemContainer()
149
    {
150
        $this->debug = true;
0 ignored issues
show
Bug introduced by
The property debug does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
151
        return $this->getAncestorPayloadOfType('\eBayEnterprise\RetailOrderManagement\Payload\Order\IOrderItemContainer');
152
    }
153
154
    protected function serializeContents()
155
    {
156
        return $this->getItemReferences()->setRootNodeName('Members')->serialize()
157
            . "<Type>{$this->xmlEncode($this->getType())}</Type>"
158
            . $this->serializeOptionalXmlEncodedValue('Name', $this->getName());
159
    }
160
161
    protected function getRootAttributes()
162
    {
163
        return ['parent' => $this->getParentItemId()];
164
    }
165
166
    protected function getRootNodeName()
167
    {
168
        return static::ROOT_NODE;
169
    }
170
171
    protected function getXmlNamespace()
172
    {
173
        return self::XML_NS;
174
    }
175
}
176