@@ -38,12 +38,19 @@ public function isLocalIp(string $ip): bool
3838 protected function ipInCidr (string $ ip , string $ cidr ): bool
3939 {
4040 [$ subnet , $ mask ] = explode ('/ ' , $ cidr );
41- if (filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) && filter_var ($ subnet , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 )) {
41+
42+ if (filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 )
43+ && filter_var ($ subnet , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 )
44+ ) {
4245 $ ipLong = ip2long ($ ip );
4346 $ subnetLong = ip2long ($ subnet );
4447 $ maskLong = -1 << (32 - (int )$ mask );
4548 return ($ ipLong & $ maskLong ) === ($ subnetLong & $ maskLong );
46- } elseif (filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) && filter_var ($ subnet , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 )) {
49+ }
50+
51+ if (filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 )
52+ && filter_var ($ subnet , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 )
53+ ) {
4754 $ ipBin = inet_pton ($ ip );
4855 $ subnetBin = inet_pton ($ subnet );
4956 $ maskBin = str_repeat ("f " , $ mask / 4 );
@@ -104,10 +111,8 @@ public function passesRules(array $geo): array|bool
104111 }
105112
106113 // Callback denial
107- if (is_callable ($ rules ['deny ' ]['callback ' ] ?? null )) {
108- if (call_user_func ($ rules ['deny ' ]['callback ' ], $ geo ) === true ) {
109- return ['reason ' => 'callback ' , 'field ' => 'callback ' ];
110- }
114+ if (is_callable ($ rules ['deny ' ]['callback ' ] ?? null ) && call_user_func ($ rules ['deny ' ]['callback ' ], $ geo ) === true ) {
115+ return ['reason ' => 'callback ' , 'field ' => 'callback ' ];
111116 }
112117
113118 // Field-based denial
@@ -122,10 +127,8 @@ public function passesRules(array $geo): array|bool
122127 }
123128
124129 // Callback allow
125- if (is_callable ($ rules ['allow ' ]['callback ' ] ?? null )) {
126- if (call_user_func ($ rules ['allow ' ]['callback ' ], $ geo ) !== true ) {
127- return ['reason ' => 'callback_allow ' , 'field ' => 'callback ' ];
128- }
130+ if (is_callable ($ rules ['allow ' ]['callback ' ] ?? null ) && call_user_func ($ rules ['allow ' ]['callback ' ], $ geo ) !== true ) {
131+ return ['reason ' => 'callback_allow ' , 'field ' => 'callback ' ];
129132 }
130133
131134 // Field-based allow
@@ -165,24 +168,13 @@ public function denyResponse(?string $reason = null, ?array $blockInfo = null):
165168 $ messageKey = 'blocked ' ;
166169 if ($ blockInfo && isset ($ blockInfo ['reason ' ])) {
167170 $ reasonType = $ blockInfo ['reason ' ];
168- switch ($ reasonType ) {
169- case 'time ' :
170- $ messageKey = 'blocked_time ' ;
171- break ;
172- case 'region ' :
173- $ messageKey = 'blocked_region ' ;
174- break ;
175- case 'city ' :
176- $ messageKey = 'blocked_city ' ;
177- break ;
178- case 'asn ' :
179- $ messageKey = 'blocked_asn ' ;
180- break ;
181- case 'country ' :
182- default :
183- $ messageKey = 'blocked ' ;
184- break ;
185- }
171+ $ messageKey = match ($ reasonType ) {
172+ 'time ' => 'blocked_time ' ,
173+ 'region ' => 'blocked_region ' ,
174+ 'city ' => 'blocked_city ' ,
175+ 'asn ' => 'blocked_asn ' ,
176+ default => 'blocked ' ,
177+ };
186178 }
187179
188180 $ message = Lang::get ('geo-restrict::messages. ' . $ messageKey );
0 commit comments