Code Duplication    Length = 33-44 lines in 7 locations

src/Model/Suppression/Bounce/IndexResponse.php 1 location

@@ 21-64 (lines=44) @@
18
/**
19
 * @author Sean Johnson <[email protected]>
20
 */
21
final class IndexResponse implements ApiResponse, PagingProvider
22
{
23
    use PaginationResponse;
24
25
    /**
26
     * @var Bounce[]
27
     */
28
    private $items;
29
30
    /**
31
     * @param Bounce[] $items
32
     */
33
    private function __construct(array $items, array $paging)
34
    {
35
        $this->items = $items;
36
        $this->paging = $paging;
37
    }
38
39
    /**
40
     * @return IndexResponse
41
     */
42
    public static function create(array $data)
43
    {
44
        $bounces = [];
45
        if (isset($data['items'])) {
46
            foreach ($data['items'] as $item) {
47
                $bounces[] = Bounce::create($item);
48
            }
49
        }
50
51
        return new self($bounces, $data['paging']);
52
    }
53
54
    /**
55
     * @return Bounce[]
56
     */
57
    public function getItems()
58
    {
59
        return $this->items;
60
    }
61
}
62

src/Model/Suppression/Complaint/IndexResponse.php 1 location

@@ 21-64 (lines=44) @@
18
/**
19
 * @author Sean Johnson <[email protected]>
20
 */
21
final class IndexResponse implements ApiResponse, PagingProvider
22
{
23
    use PaginationResponse;
24
25
    /**
26
     * @var Complaint[]
27
     */
28
    private $items;
29
30
    /**
31
     * @param Complaint[] $items
32
     */
33
    private function __construct(array $items, array $paging)
34
    {
35
        $this->items = $items;
36
        $this->paging = $paging;
37
    }
38
39
    /**
40
     * @return IndexResponse
41
     */
42
    public static function create(array $data)
43
    {
44
        $complaints = [];
45
        if (isset($data['items'])) {
46
            foreach ($data['items'] as $item) {
47
                $complaints[] = Complaint::create($item);
48
            }
49
        }
50
51
        return new self($complaints, $data['paging']);
52
    }
53
54
    /**
55
     * @return Complaint[]
56
     */
57
    public function getItems()
58
    {
59
        return $this->items;
60
    }
61
}
62

src/Model/Tag/IndexResponse.php 1 location

@@ 21-62 (lines=42) @@
18
/**
19
 * @author Tobias Nyholm <[email protected]>
20
 */
21
final class IndexResponse implements ApiResponse, PagingProvider
22
{
23
    use PaginationResponse;
24
25
    /**
26
     * @var Tag[]
27
     */
28
    private $items;
29
30
    /**
31
     * @param Tag[] $items
32
     */
33
    private function __construct(array $items, array $paging)
34
    {
35
        $this->items = $items;
36
        $this->paging = $paging;
37
    }
38
39
    /**
40
     * @return IndexResponse
41
     */
42
    public static function create(array $data)
43
    {
44
        $items = [];
45
        foreach ($data['items'] as $item) {
46
            $items[] = Tag::create($item);
47
        }
48
49
        return new self($items, $data['paging']);
50
    }
51
52
    /**
53
     * @return Tag[]
54
     */
55
    public function getItems()
56
    {
57
        return $this->items;
58
    }
59
}
60

src/Model/Event/EventResponse.php 1 location

@@ 21-53 (lines=33) @@
18
/**
19
 * @author Tobias Nyholm <[email protected]>
20
 */
21
final class EventResponse implements ApiResponse, PagingProvider
22
{
23
    use PaginationResponse;
24
    private $items;
25
26
    private function __construct()
27
    {
28
    }
29
30
    public static function create(array $data)
31
    {
32
        $events = [];
33
        if (isset($data['items'])) {
34
            foreach ($data['items'] as $item) {
35
                $events[] = Event::create($item);
36
            }
37
        }
38
39
        $model = new self();
40
        $model->items = $events;
41
        $model->paging = $data['paging'];
42
43
        return $model;
44
    }
45
46
    /**
47
     * @return Event[]
48
     */
49
    public function getItems(): array
50
    {
51
        return $this->items;
52
    }
53
}
54

src/Model/MailingList/Member/IndexResponse.php 1 location

@@ 18-55 (lines=38) @@
15
use Mailgun\Model\PaginationResponse;
16
use Mailgun\Model\ApiResponse;
17
18
final class IndexResponse implements ApiResponse, PagingProvider
19
{
20
    use PaginationResponse;
21
22
    /**
23
     * @var Member[]
24
     */
25
    private $items;
26
27
    public static function create(array $data): self
28
    {
29
        $items = [];
30
31
        if (isset($data['items'])) {
32
            foreach ($data['items'] as $item) {
33
                $items[] = Member::create($item);
34
            }
35
        }
36
37
        $model = new self();
38
        $model->items = $items;
39
        $model->paging = $data['paging'];
40
41
        return $model;
42
    }
43
44
    private function __construct()
45
    {
46
    }
47
48
    /**
49
     * @return Member[]
50
     */
51
    public function getItems(): array
52
    {
53
        return $this->items;
54
    }
55
}
56

src/Model/MailingList/PagesResponse.php 1 location

@@ 18-55 (lines=38) @@
15
use Mailgun\Model\PaginationResponse;
16
use Mailgun\Model\ApiResponse;
17
18
final class PagesResponse implements ApiResponse, PagingProvider
19
{
20
    use PaginationResponse;
21
22
    private $items;
23
24
    /**
25
     * @return self
26
     */
27
    public static function create(array $data)
28
    {
29
        $items = [];
30
31
        if (isset($data['items'])) {
32
            foreach ($data['items'] as $item) {
33
                $items[] = MailingList::create($item);
34
            }
35
        }
36
37
        $model = new self();
38
        $model->items = $items;
39
        $model->paging = $data['paging'];
40
41
        return $model;
42
    }
43
44
    private function __construct()
45
    {
46
    }
47
48
    /**
49
     * @return MailingList[]
50
     */
51
    public function getLists(): array
52
    {
53
        return $this->items;
54
    }
55
}
56

src/Model/Route/IndexResponse.php 1 location

@@ 19-57 (lines=39) @@
16
/**
17
 * @author David Garcia <[email protected]>
18
 */
19
final class IndexResponse implements ApiResponse
20
{
21
    private $totalCount;
22
    private $items;
23
24
    public static function create(array $data): self
25
    {
26
        $items = [];
27
28
        if (isset($data['items'])) {
29
            foreach ($data['items'] as $item) {
30
                $items[] = Route::create($item);
31
            }
32
        }
33
34
        $model = new self();
35
        $model->items = $items;
36
        $model->totalCount = (int) ($data['total_count'] ?? count($items));
37
38
        return $model;
39
    }
40
41
    private function __construct()
42
    {
43
    }
44
45
    public function getTotalCount(): int
46
    {
47
        return $this->totalCount;
48
    }
49
50
    /**
51
     * @return Route[]
52
     */
53
    public function getRoutes(): array
54
    {
55
        return $this->items;
56
    }
57
}
58