PrayerTimeCollection   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 49
ccs 27
cts 27
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromResponse() 0 31 1
A __construct() 0 5 1
1
<?php
2
3
namespace Ianrizky\MoslemPray\Response\MyQuran\Collection;
4
5
use Ianrizky\MoslemPray\Contracts\Response\HasPrayerTimeCollection;
6
use Ianrizky\MoslemPray\Response\MyQuran\PrayerTime;
7
use Ianrizky\MoslemPray\Support\Timezone;
8
use Illuminate\Http\Client\Response;
9
use Illuminate\Support\Carbon;
10
use Spatie\DataTransferObject\DataTransferObjectCollection;
11
12
/**
13
 * @method \Ianrizky\MoslemPray\Response\MyQuran\PrayerTime current()
14
 */
15
class PrayerTimeCollection extends DataTransferObjectCollection implements HasPrayerTimeCollection
16
{
17
    /**
18
     * Create a new instance class.
19
     *
20
     * @param  array  $collection
21
     * @return void
22
     */
23 1
    public function __construct(array $collection = [])
24
    {
25 1
        $this->collection = array_map(function ($entity) {
26 1
            return new PrayerTime($entity);
27 1
        }, $collection);
28 1
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33 1
    public static function fromResponse(Response $response)
34
    {
35 1
        $city = data_get($response->json(), 'data.lokasi');
36 1
        $timezone = Timezone::getTimezone($city, 'Asia/Jakarta');
37
38 1
        return new static(array_map(function ($entity) use ($response, $city, $timezone) {
39 1
            $date = Carbon::parse($entity['date'], $timezone);
40
41
            return [
42
                'city' => [
43 1
                    'id' => data_get($response->json(), 'data.id'),
44
                    'coordinate' => [
45 1
                        'latitude' => data_get($response->json(), 'data.koordinat.lat'),
46 1
                        'longitude' => data_get($response->json(), 'data.koordinat.lon'),
47 1
                        'latitude_degree' => data_get($response->json(), 'data.koordinat.lintang'),
48 1
                        'longitude_degree' => data_get($response->json(), 'data.koordinat.bujur'),
49
                    ],
50 1
                    'name' => $city,
51 1
                    'region' => data_get($response->json(), 'data.daerah'),
52
                ],
53 1
                'date' => $date,
54 1
                'imsak' => $date->copy()->setTimeFromTimeString($entity['imsak']),
55 1
                'subuh' => $date->copy()->setTimeFromTimeString($entity['subuh']),
56 1
                'terbit' => $date->copy()->setTimeFromTimeString($entity['terbit']),
57 1
                'dhuha' => $date->copy()->setTimeFromTimeString($entity['dhuha']),
58 1
                'dzuhur' => $date->copy()->setTimeFromTimeString($entity['dzuhur']),
59 1
                'ashar' => $date->copy()->setTimeFromTimeString($entity['ashar']),
60 1
                'maghrib' => $date->copy()->setTimeFromTimeString($entity['maghrib']),
61 1
                'isya' => $date->copy()->setTimeFromTimeString($entity['isya']),
62
            ];
63 1
        }, data_get($response->json(), 'data.jadwal', [])));
64
    }
65
}
66
67