DefaultBranchResolver::hasSupport()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 4
nc 3
nop 3
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 5
rs 9.6111
c 0
b 0
f 0
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 246
    public function hasFullBranchesSupport(string $carrier, ?string $service): bool
14
    {
15 246
        $supported = [
16 246
            Carrier::ZASILKOVNA => null,
17 246
            Carrier::CP => [
18 246
                Service::CP_NP,
19 246
                Service::CP_NB,
20 246
            ],
21 246
            Carrier::PBH => [
22 246
                Service::PBH_DHL,
23 246
                Service::PBH_SPS,
24 246
                Service::PBH_SP,
25 246
                Service::PBH_MP,
26 246
                Service::PBH_RP,
27 246
                Service::PBH_CP_NP,
28 246
                Service::PBH_INPOST_KURIER,
29 246
                Service::PBH_FAN_KURIER,
30 246
                Service::PBH_SPEEDY,
31 246
                Service::PBH_ECONT,
32 246
                Service::PBH_HR_POST,
33 246
                Service::PBH_BOX_NOW,
34 246
                Service::PBH_SI,
35 246
                Service::PBH_ITELLA,
36 246
                Service::PBH_CP_NB,
37 246
            ],
38 246
            Carrier::DPD => [
39 246
                Service::DPD_PICKUP,
40 246
            ],
41 246
            Carrier::GLS => [
42 246
                Service::GLS_SHOP,
43 246
                Service::GLS_GUARANTEED24_SHOP,
44 246
            ],
45 246
            Carrier::INTIME => [
46 246
                Service::INTIME_POSTOMAT_CZ,
47 246
                Service::INTIME_BOX_CZ,
48 246
                Service::INTIME_BOX_SK,
49 246
            ],
50 246
            Carrier::SPS => [
51 246
                Service::SPS_EXPRESS,
52 246
                Service::SPS_INTERNATIONAL,
53 246
            ],
54 246
            Carrier::SP => [
55 246
                Service::SP_BZP,
56 246
                Service::SP_BZB,
57 246
                Service::SP_EXP,
58 246
                Service::SP_EXB,
59 246
                Service::SP_BNP,
60 246
                Service::SP_BNB,
61 246
            ],
62 246
            Carrier::ULOZENKA => [
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Definitions\Carrier::ULOZENKA has been deprecated: Replaced by One by Allegro ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

62
            /** @scrutinizer ignore-deprecated */ Carrier::ULOZENKA => [

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
63 246
                Service::ULOZENKA_ULOZENKA,
64 246
                Service::ULOZENKA_DPD_PARCEL,
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Defin...ce::ULOZENKA_DPD_PARCEL has been deprecated: Renamed to ONEBYALLEGRO ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

64
                /** @scrutinizer ignore-deprecated */ Service::ULOZENKA_DPD_PARCEL,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
65 246
                Service::ULOZENKA_CP_NP,
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Defin...Service::ULOZENKA_CP_NP has been deprecated: Renamed to ONEBYALLEGRO ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

65
                /** @scrutinizer ignore-deprecated */ Service::ULOZENKA_CP_NP,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
66 246
                Service::ULOZENKA_PARTNER,
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Defin...rvice::ULOZENKA_PARTNER has been deprecated: Renamed to ONEBYALLEGRO ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

66
                /** @scrutinizer ignore-deprecated */ Service::ULOZENKA_PARTNER,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
67 246
                Service::ULOZENKA_EXPRESS_SK,
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Defin...ce::ULOZENKA_EXPRESS_SK has been deprecated: Renamed to ONEBYALLEGRO ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

67
                /** @scrutinizer ignore-deprecated */ Service::ULOZENKA_EXPRESS_SK,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
68 246
                Service::ULOZENKA_BALIKOBOX_SK,
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Defin...::ULOZENKA_BALIKOBOX_SK has been deprecated: Renamed to ONEBYALLEGRO ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

68
                /** @scrutinizer ignore-deprecated */ Service::ULOZENKA_BALIKOBOX_SK,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
69 246
                Service::ULOZENKA_DEPO_SK,
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Defin...rvice::ULOZENKA_DEPO_SK has been deprecated: Renamed to ONEBYALLEGRO ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

69
                /** @scrutinizer ignore-deprecated */ Service::ULOZENKA_DEPO_SK,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
70 246
            ],
71 246
            Carrier::PPL => [
72 246
                Service::PPL_CONNECT,
73 246
                Service::PPL_PRIVATE,
74 246
                Service::PPL_PRIVATE_SMART_CZ,
75 246
                Service::PPL_PRIVATE_SMART_EU,
76 246
            ],
77 246
            Carrier::SAMEDAY => [
78 246
                Service::SAMEDAY_LOCKER_NEXT_DAY,
79 246
                Service::SAMEDAY_LOCKER_RETURN,
80 246
                Service::SAMEDAY_CROSSBORDER_LOCKER_HD,
81 246
            ],
82 246
            Carrier::MAGYARPOSTA => null,
83 246
            Carrier::RABEN => [
84 246
                Service::RABEN_CLASSIC_TIME,
85 246
                Service::RABEN_PREMIUM_TIME,
86 246
            ],
87 246
            Carrier::DHLFREIGHTEC => [
88 246
                Service::DHLFREIGHTEC_ECD_B2B,
89 246
                Service::DHLFREIGHTEC_ECD_B2C,
90 246
            ],
91 246
            Carrier::KURIER => [
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Definitions\Carrier::KURIER has been deprecated: Terminated ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

91
            /** @scrutinizer ignore-deprecated */ Carrier::KURIER => [

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
92 246
                Service::KURIER_GARANTED,
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Defin...ervice::KURIER_GARANTED has been deprecated: Terminated ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

92
                /** @scrutinizer ignore-deprecated */ Service::KURIER_GARANTED,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
93 246
                Service::KURIER_GARANTED_BRANCH,
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Defin...:KURIER_GARANTED_BRANCH has been deprecated: Terminated ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

93
                /** @scrutinizer ignore-deprecated */ Service::KURIER_GARANTED_BRANCH,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
94 246
                Service::KURIER_STANDARD,
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Defin...ervice::KURIER_STANDARD has been deprecated: Terminated ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

94
                /** @scrutinizer ignore-deprecated */ Service::KURIER_STANDARD,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
95 246
                Service::KURIER_STANDARD_BRANCH,
0 ignored issues
show
Deprecated Code introduced by
The constant Inspirum\Balikobot\Defin...:KURIER_STANDARD_BRANCH has been deprecated: Terminated ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

95
                /** @scrutinizer ignore-deprecated */ Service::KURIER_STANDARD_BRANCH,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
96 246
            ],
97 246
            Carrier::INPOST => null,
98 246
        ];
99
100 246
        return $this->hasSupport($supported, $carrier, $service);
101
    }
102
103 242
    public function hasBranchCountryFilterSupport(string $carrier, ?string $service): bool
104
    {
105 242
        if ($service === null) {
106 1
            return true;
107
        }
108
109 241
        $supported = [
110 241
            Carrier::PPL => null,
111 241
            Carrier::DPD => null,
112 241
            Carrier::GLS => null,
113 241
            Carrier::PBH => [
114 241
                Service::PBH_DHL,
115 241
                Service::PBH_CP_NP,
116 241
                Service::PBH_SPS,
117 241
                Service::PBH_SP,
118 241
                Service::PBH_MP,
119 241
                Service::PBH_RP,
120 241
                Service::PBH_INPOST_KURIER,
121 241
                Service::PBH_FAN_KURIER,
122 241
                Service::PBH_SPEEDY,
123 241
                Service::PBH_ECONT,
124 241
                Service::PBH_HR_POST,
125 241
                Service::PBH_BOX_NOW,
126 241
                Service::PBH_SI,
127 241
                Service::PBH_ITELLA,
128 241
                Service::PBH_CP_NB,
129 241
            ],
130 241
            Carrier::SPS => null,
131 241
            Carrier::RABEN => null,
132 241
            Carrier::SAMEDAY => null,
133 241
            Carrier::ZASILKOVNA => null,
134 241
            Carrier::MAGYARPOSTA => null,
135 241
            Carrier::ONEBYALLEGRO => [
136 241
                Service::ONEBYALLEGRO_BOX_STANDARD,
137 241
                Service::ONEBYALLEGRO_POINT_STANDARD,
138 241
            ],
139 241
        ];
140
141 241
        return $this->hasSupport($supported, $carrier, $service);
142
    }
143
144
    /**
145
     * @param array<string,list<string>|null> $supported
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,list<string>|null> at position 4 could not be parsed: Expected '>' at position 4, but found 'list'.
Loading history...
146
     */
147 487
    private function hasSupport(array $supported, string $carrier, ?string $service): bool
148
    {
149 487
        foreach ($supported as $supportedCarrier => $supportedServices) {
150 487
            if ($carrier === $supportedCarrier && ($supportedServices === null || in_array($service, $supportedServices, true))) {
151 204
                return true;
152
            }
153
        }
154
155 284
        return false;
156
    }
157
}
158