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

TaxonCollection   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 107
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 14
lcom 0
cbo 1
dl 107
loc 107
ccs 0
cts 61
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 2
B createFromArray() 32 32 7
A getPage() 4 4 1
A getLimit() 4 4 1
A getPages() 4 4 1
A getTotal() 4 4 1
A getItems() 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
use FAPI\Sylius\Model\Product\Taxon as Model;
14
15
/**
16
 * @author Radoje Albijanic <[email protected]>
17
 */
18 View Code Duplication
final class TaxonCollection 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...
19
{
20
    /**
21
     * @var int
22
     */
23
    private $page;
24
25
    /**
26
     * @var int
27
     */
28
    private $limit;
29
30
    /**
31
     * @var int
32
     */
33
    private $pages;
34
35
    /**
36
     * @var int
37
     */
38
    private $total;
39
40
    /**
41
     * @var Model[]
42
     */
43
    private $items;
44
45
    private function __construct(
46
        int $page,
47
        int $limit,
48
        int $pages,
49
        int $total,
50
        array $items
51
    ) {
52
        $this->page = $page;
53
        $this->limit = $limit;
54
        $this->pages = $pages;
55
        $this->total = $total;
56
        if ([] !== $items) {
57
            $this->items = $items;
58
        }
59
    }
60
61
    /**
62
     * @return ProductCollection
63
     */
64
    public static function createFromArray(array $data): self
65
    {
66
        $page = -1;
67
        if (isset($data['page'])) {
68
            $page = $data['page'];
69
        }
70
71
        $limit = -1;
72
        if (isset($data['limit'])) {
73
            $limit = $data['limit'];
74
        }
75
76
        $pages = -1;
77
        if (isset($data['pages'])) {
78
            $pages = $data['pages'];
79
        }
80
81
        $total = -1;
82
        if (isset($data['total'])) {
83
            $total = $data['total'];
84
        }
85
86
        /** @var Variant[] $items */
87
        $items = [];
88
        if (isset($data['_embedded'], $data['_embedded']['items'])) {
89
            foreach ($data['_embedded']['items'] as $item) {
90
                $items[] = Variant::createFromArray($item);
91
            }
92
        }
93
94
        return new self($page, $limit, $pages, $total, $items);
95
    }
96
97
    public function getPage(): int
98
    {
99
        return $this->page;
100
    }
101
102
    public function getLimit(): int
103
    {
104
        return $this->limit;
105
    }
106
107
    public function getPages(): int
108
    {
109
        return $this->pages;
110
    }
111
112
    public function getTotal(): int
113
    {
114
        return $this->total;
115
    }
116
117
    /**
118
     * @return Model[]
119
     */
120
    public function getItems(): array
121
    {
122
        return $this->items;
123
    }
124
}
125