CIDR::matchBulk()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
declare(strict_types=1);
3
4
namespace hiapi\Core\Utils;
5
6
use yii\helpers\IpHelper;
7
8
class CIDR
9
{
10
    /**
11
     * @param string $ip
12
     * @param array<string, boolean> $ranges
13
     * @return bool
14
     * @throws \yii\base\NotSupportedException
15
     */
16
    public static function matchBulk(string $ip, array $ranges): bool
17
    {
18
        foreach ($ranges as $range => $_) {
19
            if (IpHelper::inRange($ip, $range)) {
20
                return true;
21
            }
22
        }
23
24
        return false;
25
    }
26
27
    public static function match(string $ip, string $range): bool
28
    {
29
        return IpHelper::inRange($ip, $range);
30
    }
31
}
32