HolidayHelper::getNextWorkday()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 13
c 1
b 0
f 1
nc 8
nop 0
dl 0
loc 18
rs 9.8333
1
<?php
2
3
namespace app\core\helpers;
4
5
use app\core\exceptions\ThirdPartyServiceErrorException;
6
use app\core\traits\SendRequestTrait;
7
use GuzzleHttp\Exception\GuzzleException;
8
use yiier\graylog\Log;
9
10
class HolidayHelper
11
{
12
    use SendRequestTrait;
13
14
    /**
15
     * @return mixed
16
     * @throws ThirdPartyServiceErrorException
17
     */
18
    public static function getNextWorkday()
19
    {
20
        $baseUrl = 'http://timor.tech/api/holiday/workday/next';
21
        /** @var HolidayHelper $self */
22
23
        try {
24
            $self = \Yii::createObject(self::class);
25
            $response = $self->sendRequest('GET', $baseUrl);
26
            $data = json_decode($response);
27
            if ($data->code == 0) {
28
                return $data->workday->date;
29
            }
30
        } catch (GuzzleException $e) {
31
            Log::error('holiday error', [$response ?? [], (string)$e]);
32
            throw new ThirdPartyServiceErrorException();
33
        } catch (\Exception $e) {
34
            Log::error('holiday error', [$response ?? [], (string)$e]);
35
            throw new ThirdPartyServiceErrorException();
36
        }
37
    }
38
}
39