Completed
Push — master ( f193cc...9d4a83 )
by Tobias
02:51
created

Product   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 1
dl 0
loc 110
ccs 0
cts 53
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B createFromArray() 0 31 8
A getId() 0 4 1
A getCode() 0 4 1
A getChannels() 0 4 1
A getTranslations() 0 4 1
A getImages() 0 4 1
A getName() 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\Product;
11
12
use FAPI\Sylius\Model\CreatableFromArray;
13
14
/**
15
 * @author Kasim Taskin <[email protected]>
16
 */
17
final class Product implements CreatableFromArray
18
{
19
    /**
20
     * @var int
21
     */
22
    private $id = 0;
23
24
    /**
25
     * @var null|string
26
     */
27
    private $name;
28
29
    /**
30
     * @var null|string
31
     */
32
    private $code = '';
33
34
    /**
35
     * @var string[]
36
     */
37
    private $channels = [];
38
39
    /**
40
     * @var string[][]
41
     */
42
    private $translations = [];
43
44
    /**
45
     * @var Image[]
46
     */
47
    private $images = [];
48
49
    private function __construct()
50
    {
51
    }
52
53
    /**
54
     * @return Product
55
     */
56
    public static function createFromArray(array $data): self
57
    {
58
        $model = new self();
59
        if (isset($data['id'])) {
60
            $model->id = $data['id'];
61
        }
62
63
        if (isset($data['code'])) {
64
            $model->code = $data['code'];
65
        }
66
        if (isset($data['name'])) {
67
            $model->name = $data['name'];
68
        }
69
70
        if (isset($data['channels'])) {
71
            $model->channels = $data['channels'];
72
        }
73
74
        $translations = [];
0 ignored issues
show
Unused Code introduced by
$translations is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
75
        if (isset($data['translations'])) {
76
            $model->translations = $data['translations'];
77
        }
78
79
        if (isset($data['images'])) {
80
            foreach ($data['images'] as $image) {
81
                $model->images[] = Image::createFromArray($image);
82
            }
83
        }
84
85
        return $model;
86
    }
87
88
    public function getId(): int
89
    {
90
        return $this->id;
91
    }
92
93
    public function getCode(): string
94
    {
95
        return $this->code;
96
    }
97
98
    /**
99
     * @return string[]
100
     */
101
    public function getChannels(): array
102
    {
103
        return $this->channels;
104
    }
105
106
    /**
107
     * @return \string[][]
108
     */
109
    public function getTranslations(): array
110
    {
111
        return $this->translations;
112
    }
113
114
    /**
115
     * @return Image[]
116
     */
117
    public function getImages(): array
118
    {
119
        return $this->images;
120
    }
121
122
    public function getName(): ?string
123
    {
124
        return $this->name;
125
    }
126
}
127