Completed
Push — master ( 0d32ff...033f11 )
by Mikołaj
05:00
created

ShippingGateway::getShippingMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file has been created by the developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusShippingExportPlugin\Entity;
14
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Doctrine\Common\Collections\Collection;
17
use Sylius\Component\Core\Model\ShippingMethodInterface;
18
use Webmozart\Assert\Assert;
19
20
class ShippingGateway implements ShippingGatewayInterface
21
{
22
    /**
23
     * @var int
24
     */
25
    protected $id;
26
27
    /**
28
     * @var string
29
     */
30
    protected $code;
31
32
    /**
33
     * @var string
34
     */
35
    protected $label;
36
37
    /**
38
     * @var array
39
     */
40
    protected $config;
41
42
    /**
43
     * @var Collection|ShippingMethodInterface[]
44
     */
45
    protected $shippingMethods;
46
47
    /**
48
     * @var Collection|ShippingExportInterface[]
49
     */
50
    protected $shippingExports;
51
52
    public function __construct()
53
    {
54
        $this->shippingExports = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type object<Doctrine\Common\C...ippingExportInterface>> of property $shippingExports.

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...
55
        $this->shippingMethods = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type object<Doctrine\Common\C...ippingMethodInterface>> of property $shippingMethods.

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
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getId(): ?int
62
    {
63
        return $this->id;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function setCode(?string $code): void
70
    {
71
        $this->code = $code;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getCode(): ?string
78
    {
79
        return $this->code;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function setLabel(?string $label): void
86
    {
87
        $this->label = $label;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function getLabel(): ?string
94
    {
95
        return $this->label;
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function setConfig(?array $config): void
102
    {
103
        $this->config = $config;
0 ignored issues
show
Documentation Bug introduced by
It seems like $config can be null. However, the property $config is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

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

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function getConfig(): ?array
110
    {
111
        return $this->config;
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function getConfigValue(string $key): ?string
118
    {
119
        Assert::keyExists($this->config, $key, sprintf(
120
            'Shipping gateway config named %s does not exist.',
121
            $key
122
        ));
123
124
        return $this->config[$key];
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130
    public function getShippingMethods(): ?Collection
131
    {
132
        return $this->shippingMethods;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->shippingMethods; of type Doctrine\Common\Collecti...ippingMethodInterface[] adds the type Sylius\Component\Core\Mo...ippingMethodInterface[] to the return on line 132 which is incompatible with the return type declared by the interface BitBag\SyliusShippingExp...ace::getShippingMethods of type Doctrine\Common\Collections\Collection|null.
Loading history...
133
    }
134
135
    /**
136
     * {@inheritdoc}
137
     */
138
    public function addShippingMethod(ShippingMethodInterface $shippingMethod): void
139
    {
140
        if (!$this->hasShippingMethod($shippingMethod)) {
141
            $this->shippingMethods->add($shippingMethod);
142
        }
143
    }
144
145
    /**
146
     * {@inheritdoc}
147
     */
148
    public function removeShippingMethod(ShippingMethodInterface $shippingMethod): void
149
    {
150
        if ($this->hasShippingMethod($shippingMethod)) {
151
            $this->shippingMethods->removeElement($shippingMethod);
152
        }
153
    }
154
155
    /**
156
     * {@inheritdoc}
157
     */
158
    public function hasShippingMethod(ShippingMethodInterface $shippingMethod): bool
159
    {
160
        return $this->shippingMethods->contains($shippingMethod);
161
    }
162
163
    /**
164
     * {@inheritdoc}
165
     */
166
    public function getShippingExports(): ?Collection
167
    {
168
        return $this->shippingExports;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->shippingExports; of type Doctrine\Common\Collecti...ippingExportInterface[] adds the type BitBag\SyliusShippingExp...ippingExportInterface[] to the return on line 168 which is incompatible with the return type declared by the interface BitBag\SyliusShippingExp...ace::getShippingExports of type Doctrine\Common\Collections\Collection|null.
Loading history...
169
    }
170
171
    /**
172
     * {@inheritdoc}
173
     */
174
    public function addShippingExport(ShippingExportInterface $shippingExport): void
175
    {
176
        if (!$this->hasShippingExport($shippingExport)) {
177
            $this->shippingExports->add($shippingExport);
178
            $shippingExport->setShippingGateway($this);
179
        }
180
    }
181
182
    /**
183
     * {@inheritdoc}
184
     */
185
    public function removeShippingExport(ShippingExportInterface $shippingExport): void
186
    {
187
        if ($this->hasShippingExport($shippingExport)) {
188
            $this->shippingExports->removeElement($shippingExport);
189
        }
190
    }
191
192
    /**
193
     * {@inheritdoc}
194
     */
195
    public function hasShippingExport(ShippingExportInterface $shippingExport): bool
196
    {
197
        return $this->shippingExports->contains($shippingExport);
198
    }
199
}
200