Passed
Branch master (0d8fc3)
by Tomáš
12:26
created

DefaultBranchResolver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 67
c 1
b 0
f 1
dl 0
loc 94
ccs 11
cts 11
cp 1
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hasBranchCountryFilterSupport() 0 18 2
B hasFullBranchesSupport() 0 72 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\Branch;
6
7
use Inspirum\Balikobot\Definitions\Carrier;
8
use Inspirum\Balikobot\Definitions\Service;
9
use function in_array;
10
11
final class DefaultBranchResolver implements BranchResolver
12
{
13 223
    public function hasFullBranchesSupport(string $carrier, ?string $service): bool
14
    {
15 223
        $supported = [
16
            Carrier::ZASILKOVNA => null,
17
            Carrier::CP         => [
18
                Service::CP_NP,
19
                Service::CP_NB,
20
            ],
21
            Carrier::PBH        => [
22
                Service::PBH_UPS,
23
                Service::PBH_SP,
24
                Service::PBH_MP,
25
                Service::PBH_RP,
26
                Service::PBH_CP_NP,
27
                Service::PBH_INPOST_KURIER,
28
                Service::PBH_FAN_KURIER,
29
                Service::PBH_SPEEDY,
30
                Service::PBH_NOBA_POSHTA,
31
                Service::PBH_ECONT,
32
            ],
33
            Carrier::DPD        => [
34
                Service::DPD_PICKUP,
35
            ],
36
            Carrier::GLS        => [
37
                Service::GLS_SHOP,
38
                Service::GLS_GUARANTEED24_SHOP,
39
            ],
40
            Carrier::INTIME     => [
41
                Service::INTIME_POSTOMAT_CZ,
42
                Service::INTIME_BOX_CZ,
43
                Service::INTIME_BOX_SK,
44
            ],
45
            Carrier::SPS        => [
46
                Service::SPS_EXPRESS,
47
                Service::SPS_INTERNATIONAL,
48
            ],
49
            Carrier::SP         => [
50
                Service::SP_BZP,
51
                Service::SP_BZB,
52
                Service::SP_EXP,
53
                Service::SP_EXB,
54
                Service::SP_BNP,
55
                Service::SP_BNB,
56
            ],
57
            Carrier::ULOZENKA   => [
58
                Service::ULOZENKA_ULOZENKA,
59
                Service::ULOZENKA_DPD_PARCEL,
60
                Service::ULOZENKA_CP_NP,
61
                Service::ULOZENKA_PARTNER,
62
                Service::ULOZENKA_EXPRESS_SK,
63
                Service::ULOZENKA_BALIKOBOX_SK,
64
                Service::ULOZENKA_DEPO_SK,
65
            ],
66
            Carrier::PPL        => [
67
                Service::PPL_CONNECT,
68
                Service::PPL_PRIVATE,
69
                Service::PPL_PRIVATE_SMART_CZ,
70
                Service::PPL_PRIVATE_SMART_EU,
71
            ],
72
            Carrier::SAMEDAY        => [
73
                Service::SAMEDAY_LOCKER_NEXT_DAY,
74
                Service::SAMEDAY_LOCKER_RETURN,
75
            ],
76
        ];
77
78 223
        foreach ($supported as $supportedCarrier => $supportedServices) {
79 223
            if ($carrier === $supportedCarrier && ($supportedServices === null || in_array($service, $supportedServices, true))) {
80 78
                return true;
81
            }
82
        }
83
84 147
        return false;
85
    }
86
87 215
    public function hasBranchCountryFilterSupport(string $carrier, ?string $service): bool
88
    {
89 215
        if ($service === null) {
90 1
            return true;
91
        }
92
93 214
        $supportedCarriers = [
94
            Carrier::PPL,
95
            Carrier::DPD,
96
            Carrier::GLS,
97
            Carrier::ULOZENKA,
98
            Carrier::PBH,
99
            Carrier::SPS,
100
            Carrier::RABEN,
101
            Carrier::SAMEDAY,
102
        ];
103
104 214
        return in_array($carrier, $supportedCarriers, true);
105
    }
106
}
107