WorkingHours::getDayName()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 13
ccs 0
cts 11
cp 0
crap 12
rs 10
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\Core\ArrayOf;
17
use Appwilio\RussianPostSDK\Dispatching\DataAware;
18
use Appwilio\RussianPostSDK\Dispatching\Instantiator;
19
20
final class WorkingHours
21
{
22
    use DataAware;
23
    use TimeIntervalAware;
24
25
    public function getDayNumber(): ?int
26
    {
27
        return $this->get('weekday-id', 'int');
28
    }
29
30
    public function getDayName(?string $locale = null): ?string
31
    {
32
        if (null === $this->getDayNumber()) {
33
            return null;
34
        }
35
36
        if ($this->get('weekday-name')) {
37
            return $this->get('weekday-name');
38
        }
39
40
        return (new \IntlDateFormatter(
41
            $locale ?? 'ru_RU', \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, null, 'EEEE'
42
        ))->format(\strtotime("next Sunday + {$this->getDayNumber()} days"));
43
    }
44
45
    /**
46
     * @return Lunch[]|null
47
     */
48
    public function getLunches()
49
    {
50
        return Instantiator::instantiate(new ArrayOf(Lunch::class), $this->get('lunches'));
51
    }
52
53
    protected function getBeginValue()
54
    {
55
        return $this->get('begin-worktime');
56
    }
57
58
    protected function getEndValue()
59
    {
60
        return $this->get('end-worktime');
61
    }
62
}
63