Variant   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 93
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 93
loc 93
ccs 22
cts 28
cp 0.7856
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A createFromArray() 24 24 5
A getId() 4 4 1
A getCode() 4 4 1
A getTranslations() 4 4 1
A getChannelPricings() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
final class Variant 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
    /**
35
     * @var string[][]
36
     */
37
    private $channelPricings;
38
39
    /**
40
     * Variant constructor.
41
     *
42
     * @param string[][] $translations
43
     */
44 1
    private function __construct(
45
        int $id,
46
        string $code,
47
        array $translations,
48
        array $channelPricings
49
    ) {
50 1
        $this->id = $id;
51 1
        $this->code = $code;
52 1
        $this->translations = $translations;
53 1
        $this->channelPricings = $channelPricings;
54 1
    }
55
56
    /**
57
     * @return Variant
58
     */
59 1
    public static function createFromArray(array $data): self
60
    {
61 1
        $id = -1;
62 1
        if (isset($data['id'])) {
63 1
            $id = $data['id'];
64
        }
65
66 1
        $code = '';
67 1
        if (isset($data['code'])) {
68 1
            $code = $data['code'];
69
        }
70
71 1
        $translations = [];
72 1
        if (isset($data['translations'])) {
73 1
            $translations = $data['translations'];
74
        }
75
76 1
        $channelPricings = [];
77 1
        if (isset($data['channelPricings'])) {
78 1
            $channelPricings = $data['channelPricings'];
79
        }
80
81 1
        return new self($id, $code, $translations, $channelPricings);
82
    }
83
84 1
    public function getId(): int
85
    {
86 1
        return $this->id;
87
    }
88
89
    public function getCode(): string
90
    {
91
        return $this->code;
92
    }
93
94
    /**
95
     * @return \string[][]
96
     */
97
    public function getTranslations(): array
98
    {
99
        return $this->translations;
100
    }
101
102
    /**
103
     * @return \string[][]
104
     */
105
    public function getChannelPricings(): array
106
    {
107
        return $this->channelPricings;
108
    }
109
}
110