Completed
Push — master ( bba068...3760af )
by Tobias
02:03
created

Taxon::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 0
cts 9
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
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 Radoje Albijanic <[email protected]>
16
 */
17 View Code Duplication
final class Taxon implements CreatableFromArray
0 ignored issues
show
Duplication introduced by
This class 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...
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 $translations;
33
34
    private function __construct(
35
        int $id,
36
        string $code,
37
        array $translations
38
    ) {
39
        $this->id = $id;
40
        $this->code = $code;
41
        $this->translations = $translations;
42
    }
43
44
    public static function createFromArray(array $data): self
45
    {
46
        $id = -1;
47
        if (isset($data['id'])) {
48
            $id = $data['id'];
49
        }
50
51
        $code = '';
52
        if (isset($data['code'])) {
53
            $code = $data['code'];
54
        }
55
56
        $translations = [];
57
        if (isset($data['translations'])) {
58
            $translations = $data['translations'];
59
        }
60
61
        return new self($id, $code, $translations);
62
    }
63
64
    public function getId(): int
65
    {
66
        return $this->id;
67
    }
68
69
    public function getCode(): string
70
    {
71
        return $this->code;
72
    }
73
74
    /**
75
     * @return \string[][]
76
     */
77
    public function getTranslations(): array
78
    {
79
        return $this->translations;
80
    }
81
}
82