Completed
Push — master ( 6a943d...2b60fb )
by David
02:17
created

IndexResponse::getTotalCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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\Route;
13
14
use Mailgun\Model\ApiResponse;
15
16
/**
17
 * @author David Garcia <[email protected]>
18
 */
19 View Code Duplication
final class IndexResponse implements ApiResponse
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...
20
{
21
    /**
22
     * @var int
23
     */
24
    private $totalCount;
25
26
    /**
27
     * @var Route[]
28
     */
29
    private $items;
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 1
    public static function create(array $data)
35
    {
36 1
        $items = [];
37
38 1
        if (isset($data['items'])) {
39 1
            foreach ($data['items'] as $item) {
40 1
                $items[] = Route::create($item);
41
            }
42
        }
43
44 1
        if (isset($data['total_count'])) {
45 1
            $count = $data['total_count'];
46
        } else {
47
            $count = count($items);
48
        }
49
50 1
        return new self($count, $items);
51
    }
52
53
    /**
54
     * @param int     $totalCount
55
     * @param Route[] $items
56
     */
57 1
    private function __construct($totalCount, array $items)
58
    {
59 1
        $this->totalCount = $totalCount;
60 1
        $this->items = $items;
61 1
    }
62
63
    /**
64
     * @return int
65
     */
66 1
    public function getTotalCount()
67
    {
68 1
        return $this->totalCount;
69
    }
70
71
    /**
72
     * @return Route[]
73
     */
74 1
    public function getRoutes()
75
    {
76 1
        return $this->items;
77
    }
78
}
79