Passed
Push — master ( 399e0c...27510f )
by Jhao
02:16
created

WorkingHours   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 41
ccs 0
cts 27
cp 0
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDayNumber() 0 3 1
A getLunches() 0 3 1
A getBeginValue() 0 3 1
A getDayName() 0 13 3
A getEndValue() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of RussianPost SDK package.
5
 *
6
 * © Appwilio (http://appwilio.com), JhaoDa (https://github.com/jhaoda)
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\PostOffices\Responses;
15
16
use Appwilio\RussianPostSDK\Dispatching\DataAware;
17
use Appwilio\RussianPostSDK\Dispatching\Instantiator;
18
use Appwilio\RussianPostSDK\Dispatching\Http\ArrayOf;
19
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable;
20
21
final class WorkingHours implements Arrayable
22
{
23
    use DataAware;
24
    use TimeIntervalAware;
25
26
    public function getDayNumber(): ?int
27
    {
28
        return $this->get('weekday-id', 'int');
29
    }
30
31
    public function getDayName(?string $locale = null): ?string
32
    {
33
        if (null === $this->getDayNumber()) {
34
            return null;
35
        }
36
37
        if ($this->get('weekday-name')) {
38
            return $this->get('weekday-name');
39
        }
40
41
        return (new \IntlDateFormatter(
42
            $locale ?? 'ru_RU', \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, null, 'EEEE'
43
        ))->format(\strtotime("next Sunday + {$this->getDayNumber()} days"));
44
    }
45
46
    /**
47
     * @return Lunch[]|null
48
     */
49
    public function getLunches()
50
    {
51
        return Instantiator::instantiate(new ArrayOf(Lunch::class), $this->get('lunches'));
52
    }
53
54
    protected function getBeginValue()
55
    {
56
        return $this->get('begin-worktime');
57
    }
58
59
    protected function getEndValue()
60
    {
61
        return $this->get('end-worktime');
62
    }
63
}
64