NewslistResponse::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Igorsgm\TibiaDataApi\Response;
4
5
use Carbon\Carbon;
6
use Igorsgm\TibiaDataApi\Models\Newslist;
7
use Igorsgm\TibiaDataApi\Models\Newslist\News;
8
9
class NewslistResponse extends AbstractResponse
10
{
11
12
    /**
13
     * @var Newslist
14
     */
15
    private $newslist;
16
17
    /**
18
     * NewslistResponse constructor.
19
     * @param  \stdClass  $response
20
     * @throws \Igorsgm\TibiaDataApi\Exceptions\ImmutableException
21
     * @throws \Exception
22
     */
23
    public function __construct(\stdClass $response)
24
    {
25
        $news = collect();
26
        foreach ($response->newslist->data as $item) {
27
            $news->push(new News(
28
                $item->id,
29
                $item->type,
30
                $item->news,
31
                $item->apiurl,
32
                $item->tibiaurl,
33
                new Carbon($item->date->date, $item->date->timezone)
34
            ));
35
        }
36
37
        $this->newslist = new Newslist($response->newslist->type, $news);
38
39
        parent::__construct($response);
40
    }
41
42
    /**
43
     * @return Newslist
44
     */
45
    public function getNewslist(): Newslist
46
    {
47
        return $this->newslist;
48
    }
49
}
50