Code Duplication    Length = 44-45 lines in 2 locations

src/Model/Domain/CredentialResponse.php 1 location

@@ 19-62 (lines=44) @@
16
/**
17
 * @author Sean Johnson <[email protected]>
18
 */
19
final class CredentialResponse implements ApiResponse
20
{
21
    private $totalCount;
22
    private $items;
23
24
    public static function create(array $data): self
25
    {
26
        $items = [];
27
        if (isset($data['items'])) {
28
            foreach ($data['items'] as $item) {
29
                $items[] = CredentialResponseItem::create($item);
30
            }
31
        }
32
33
        if (isset($data['total_count'])) {
34
            $count = (int) $data['total_count'];
35
        } else {
36
            $count = count($items);
37
        }
38
39
        $model = new self();
40
        $model->totalCount = $count;
41
        $model->items = $items;
42
43
        return $model;
44
    }
45
46
    private function __construct()
47
    {
48
    }
49
50
    public function getTotalCount(): int
51
    {
52
        return $this->totalCount;
53
    }
54
55
    /**
56
     * @return CredentialResponseItem[]
57
     */
58
    public function getCredentials(): array
59
    {
60
        return $this->items;
61
    }
62
}
63

src/Model/Domain/IndexResponse.php 1 location

@@ 19-63 (lines=45) @@
16
/**
17
 * @author Sean Johnson <[email protected]>
18
 */
19
final class IndexResponse implements ApiResponse
20
{
21
    private $totalCount;
22
    private $items;
23
24
    public static function create(array $data): self
25
    {
26
        $items = [];
27
28
        if (isset($data['items'])) {
29
            foreach ($data['items'] as $item) {
30
                $items[] = Domain::create($item);
31
            }
32
        }
33
34
        if (isset($data['total_count'])) {
35
            $count = $data['total_count'];
36
        } else {
37
            $count = count($items);
38
        }
39
40
        $model = new self();
41
        $model->totalCount = $count;
42
        $model->items = $items;
43
44
        return $model;
45
    }
46
47
    private function __construct()
48
    {
49
    }
50
51
    public function getTotalCount(): int
52
    {
53
        return $this->totalCount;
54
    }
55
56
    /**
57
     * @return Domain[]
58
     */
59
    public function getDomains(): array
60
    {
61
        return $this->items;
62
    }
63
}
64