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

IndexResponse   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 57
loc 57
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 3 3 1
A create() 16 16 3
A getItems() 4 4 1
A getTotalCount() 8 8 2

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
 * 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