PaymentMethod   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 85
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 85
loc 85
ccs 0
cts 47
cp 0
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 getName() 4 4 1
A getDescription() 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\Checkout;
11
12
use FAPI\Sylius\Model\CreatableFromArray;
13
14
/**
15
 * @author Kasim Taskin <[email protected]>
16
 */
17 View Code Duplication
final class PaymentMethod 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 $name;
33
34
    /**
35
     * @var string
36
     */
37
    private $description;
38
39
    /**
40
     * PaymentMethod constructor.
41
     */
42
    private function __construct(
43
        int $id,
44
        string $code,
45
        string $name,
46
        string $description
47
    ) {
48
        $this->id = $id;
49
        $this->code = $code;
50
        $this->name = $name;
51
        $this->description = $description;
52
    }
53
54
    /**
55
     * @return ShipmentMethod
56
     */
57
    public static function createFromArray(array $data): self
58
    {
59
        $id = -1;
60
        if (isset($data['id'])) {
61
            $id = $data['id'];
62
        }
63
64
        $code = '';
65
        if (isset($data['code'])) {
66
            $code = $data['code'];
67
        }
68
69
        $name = '';
70
        if (isset($data['name'])) {
71
            $name = $data['name'];
72
        }
73
74
        $description = '';
75
        if (isset($data['description'])) {
76
            $description = $data['description'];
77
        }
78
79
        return new self($id, $code, $name, $description);
80
    }
81
82
    public function getId(): int
83
    {
84
        return $this->id;
85
    }
86
87
    public function getCode(): string
88
    {
89
        return $this->code;
90
    }
91
92
    public function getName(): string
93
    {
94
        return $this->name;
95
    }
96
97
    public function getDescription(): string
98
    {
99
        return $this->description;
100
    }
101
}
102