ShipmentMethod   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 0
dl 0
loc 102
ccs 0
cts 57
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
B createFromArray() 0 29 6
A getId() 0 4 1
A getCode() 0 4 1
A getName() 0 4 1
A getDescription() 0 4 1
A getPrice() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace FAPI\Sylius\Model\Checkout;
11
12
use FAPI\Sylius\Model\CreatableFromArray;
13
14
/**
15
 * @author Kasim Taskin <[email protected]>
16
 */
17
final class ShipmentMethod implements CreatableFromArray
18
{
19
    /**
20
     * @var int
21
     */
22
    private $id;
23
24
    /**
25
     * @var string
26
     */
27
    private $code;
28
29
    /**
30
     * @var string
31
     */
32
    private $name;
33
34
    /**
35
     * @var string
36
     */
37
    private $description;
38
39
    /**
40
     * @var int
41
     */
42
    private $price;
43
44
    /**
45
     * ShipmentMethod constructor.
46
     */
47
    private function __construct(
48
        int $id,
49
        string $code,
50
        string $name,
51
        string $description,
52
        int $price
53
    ) {
54
        $this->id = $id;
55
        $this->code = $code;
56
        $this->name = $name;
57
        $this->description = $description;
58
        $this->price = $price;
59
    }
60
61
    /**
62
     * @return ShipmentMethod
63
     */
64
    public static function createFromArray(array $data): self
65
    {
66
        $id = -1;
67
        if (isset($data['id'])) {
68
            $id = $data['id'];
69
        }
70
71
        $code = '';
72
        if (isset($data['code'])) {
73
            $code = $data['code'];
74
        }
75
76
        $name = '';
77
        if (isset($data['name'])) {
78
            $name = $data['name'];
79
        }
80
81
        $description = '';
82
        if (isset($data['description'])) {
83
            $description = $data['description'];
84
        }
85
86
        $price = -1;
87
        if (isset($data['price'])) {
88
            $price = $data['price'];
89
        }
90
91
        return new self($id, $code, $name, $description, $price);
92
    }
93
94
    public function getId(): int
95
    {
96
        return $this->id;
97
    }
98
99
    public function getCode(): string
100
    {
101
        return $this->code;
102
    }
103
104
    public function getName(): string
105
    {
106
        return $this->name;
107
    }
108
109
    public function getDescription(): string
110
    {
111
        return $this->description;
112
    }
113
114
    public function getPrice(): int
115
    {
116
        return $this->price;
117
    }
118
}
119