Payment   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 38
loc 38
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A createFromArray() 9 9 2
A getMethods() 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 Payment 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 PaymentMethod[]
21
     */
22
    private $methods;
23
24
    /**
25
     * Payment constructor.
26
     *
27
     * @param array|PaymentMethod[] $methods
28
     */
29
    private function __construct(array $methods)
30
    {
31
        $this->methods = $methods;
32
    }
33
34
    /**
35
     * @return Payment
36
     */
37
    public static function createFromArray(array $data): self
38
    {
39
        $methods = [];
40
        foreach ($data['methods'] as $method) {
41
            $methods[] = PaymentMethod::createFromArray($method);
42
        }
43
44
        return new self($methods);
45
    }
46
47
    /**
48
     * @return PaymentMethod[]
49
     */
50
    public function getMethods(): array
51
    {
52
        return $this->methods;
53
    }
54
}
55