HolidayHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
c 1
b 0
f 1
dl 0
loc 26
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A getNextWorkday() 0 18 4
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