These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * Copyright (C) 2013-2016 Mailgun |
||
5 | * |
||
6 | * This software may be modified and distributed under the terms |
||
7 | * of the MIT license. See the LICENSE file for details. |
||
8 | */ |
||
9 | |||
10 | namespace Mailgun\Resource\Api\Routes\Response; |
||
11 | |||
12 | use Mailgun\Resource\Api\Routes\Dto\RouteDto; |
||
13 | use Mailgun\Resource\ApiResponse; |
||
14 | |||
15 | /** |
||
16 | * @author David Garcia <[email protected]> |
||
17 | */ |
||
18 | View Code Duplication | final class IndexResponse implements ApiResponse |
|
0 ignored issues
–
show
|
|||
19 | { |
||
20 | /** |
||
21 | * @var int |
||
22 | */ |
||
23 | private $totalCount; |
||
24 | |||
25 | /** |
||
26 | * @var RouteDto[] |
||
27 | */ |
||
28 | private $items; |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | public static function create(array $data) |
||
34 | { |
||
35 | $items = []; |
||
36 | |||
37 | if (isset($data['items'])) { |
||
38 | foreach ($data['items'] as $item) { |
||
39 | $items[] = RouteDto::create($item); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | if (isset($data['total_count'])) { |
||
44 | $count = $data['total_count']; |
||
45 | } else { |
||
46 | $count = count($items); |
||
47 | } |
||
48 | |||
49 | return new self($count, $items); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param int $totalCount |
||
54 | * @param RouteDto[] $items |
||
55 | */ |
||
56 | private function __construct($totalCount, array $items) |
||
57 | { |
||
58 | $this->totalCount = $totalCount; |
||
59 | $this->items = $items; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @return int |
||
64 | */ |
||
65 | public function getTotalCount() |
||
66 | { |
||
67 | return $this->totalCount; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return RouteDto[] |
||
72 | */ |
||
73 | public function getRoutes() |
||
74 | { |
||
75 | return $this->items; |
||
76 | } |
||
77 | } |
||
78 |
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.