ProductConfiguration::getDeliveryMethods()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Bpost\BpostApiClient\Bpost;
5
6
use Bpost\BpostApiClient\Bpost\ProductConfiguration\DeliveryMethod;
7
use SimpleXMLElement;
8
9
/**
10
 * Class ProductConfiguration
11
 */
12
class ProductConfiguration
13
{
14
    private array $deliveryMethods = [];
15
16
    public function getDeliveryMethods(): array
17
    {
18
        return $this->deliveryMethods;
19
    }
20
21
    public function addDeliveryMethod(DeliveryMethod $deliveryMethod): void
22
    {
23
        $this->deliveryMethods[] = $deliveryMethod;
24
    }
25
26
    public static function createFromXML(SimpleXMLElement $xml): self
27
    {
28
        $productConfiguration = new self();
29
30
        if (isset($xml->deliveryMethod)) {
31
            foreach ($xml->deliveryMethod as $deliveryMethodXml) {
32
                $productConfiguration->addDeliveryMethod(
33
                    DeliveryMethod::createFromXML($deliveryMethodXml)
0 ignored issues
show
Bug introduced by
It seems like $deliveryMethodXml can also be of type null; however, parameter $xml of Bpost\BpostApiClient\Bpo...Method::createFromXML() does only seem to accept SimpleXMLElement, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
                    DeliveryMethod::createFromXML(/** @scrutinizer ignore-type */ $deliveryMethodXml)
Loading history...
34
                );
35
            }
36
        }
37
38
        return $productConfiguration;
39
    }
40
}
41