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);
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.