Completed
Push — master ( 1fd018...1044a6 )
by David
20:21
created

IndexResponse::getTotalCount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2013 Mailgun
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license. See the LICENSE file for details.
10
 */
11
12
namespace Mailgun\Model\Suppression\Whitelist;
13
14
use Mailgun\Model\ApiResponse;
15
use Mailgun\Model\PaginationResponse;
16
use Mailgun\Model\PagingProvider;
17
18
/**
19
 * @author Artem Bondarenko <[email protected]>
20
 */
21 View Code Duplication
final class IndexResponse implements ApiResponse, PagingProvider
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...
22
{
23
    use PaginationResponse;
24
25
    /**
26
     * Array to store a list of whitelist items from
27
     * index response.
28
     *
29
     * @var Whitelist[]
30
     */
31
    private $items = [];
32
33
    /**
34
     * Store the total number of whitelists items.
35
     *
36
     * @var int
37
     */
38
    private $totalCount;
39
40
    private function __construct()
41
    {
42
    }
43
44
    public static function create(array $data): self
45
    {
46
        $whitelists = [];
47
48
        if (isset($data['items'])) {
49
            foreach ($data['items'] as $item) {
50
                $whitelists[] = Whitelist::create($item);
51
            }
52
        }
53
54
        $model = new self();
55
        $model->items = $whitelists;
56
        $model->paging = $data['paging'];
57
58
        return $model;
59
    }
60
61
    /**
62
     * @return Whitelist[]
63
     */
64
    public function getItems(): array
65
    {
66
        return $this->items;
67
    }
68
69
    public function getTotalCount(): int
70
    {
71
        if (null === $this->totalCount) {
72
            $this->totalCount = count($this->items);
73
        }
74
75
        return $this->totalCount;
76
    }
77
}
78