Completed
Push — master ( ac056e...2fe264 )
by David
04:27 queued 01:15
created

IndexResponse   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 39
loc 39
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 16 16 3
A __construct() 3 3 1
A getTotalCount() 4 4 1
A getRoutes() 4 4 1

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\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
    private $totalCount;
22
    private $items;
23
24 1
    public static function create(array $data): self
25
    {
26 1
        $items = [];
27
28 1
        if (isset($data['items'])) {
29 1
            foreach ($data['items'] as $item) {
30 1
                $items[] = Route::create($item);
31
            }
32
        }
33
34 1
        $model = new self();
35 1
        $model->items = $items;
36 1
        $model->totalCount = (int) ($data['total_count'] ?? count($items));
37
38 1
        return $model;
39
    }
40
41 1
    private function __construct()
42
    {
43 1
    }
44
45 1
    public function getTotalCount(): int
46
    {
47 1
        return $this->totalCount;
48
    }
49
50
    /**
51
     * @return Route[]
52
     */
53 1
    public function getRoutes(): array
54
    {
55 1
        return $this->items;
56
    }
57
}
58