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 $page;
23
24
/**
25
* @var int
26
*/
27
private $limit;
28
29
/**
30
* @var int
31
*/
32
private $pages;
33
34
/**
35
* @var int
36
*/
37
private $total;
38
39
/**
40
* @var Product[]
41
*/
42
private $items;
43
44
private function __construct(
45
int $page,
46
int $limit,
47
int $pages,
48
int $total,
49
array $items
50
) {
51
$this->page = $page;
52
$this->limit = $limit;
53
$this->pages = $pages;
54
$this->total = $total;
55
if ([] !== $items) {
56
$this->items = $items;
57
}
58
}
59
60
/**
61
* @return ProductCollection
62
*/
63
public static function createFromArray(array $data): self
64
{
65
$page = -1;
66
if (isset($data['page'])) {
67
$page = $data['page'];
68
}
69
70
$limit = -1;
71
if (isset($data['limit'])) {
72
$limit = $data['limit'];
73
}
74
75
$pages = -1;
76
if (isset($data['pages'])) {
77
$pages = $data['pages'];
78
}
79
80
$total = -1;
81
if (isset($data['total'])) {
82
$total = $data['total'];
83
}
84
85
/** @var Product[] $items */
86
$items = [];
87
if (isset($data['_embedded'], $data['_embedded']['items'])) {
88
foreach ($data['_embedded']['items'] as $item) {
89
$items[] = Product::createFromArray($item);
90
}
91
}
92
93
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.