Completed
Pull Request — master (#32)
by Manuel
04:01
created

ExtractNetwork::fromIp()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.9102

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
ccs 8
cts 13
cp 0.6153
rs 9.2
c 1
b 0
f 0
cc 4
eloc 8
nc 4
nop 1
crap 4.9102
1
<?php
2
3
namespace PiFinder\Utilities;
4
5
class ExtractNetwork
6
{
7
    /**
8
     * Extract the network from the ip address.
9
     *
10
     * @param string $ip
11
     *
12
     * @return string $network
13
     */
14 5
    public static function fromIp($ip)
15
    {
16 5
        if (starts_with($ip, '192.168.')) {
17 5
            return '192.168.0.0/16';
18
        }
19
20 1
        if (starts_with($ip, '10.')) {
21 1
            return '10.0.0.0/8';
22
        }
23
24 1
        if (preg_match('/^172\.(1[6-9]|2[0-9]|3[01])\./', $ip)) {
25 1
            return '172.16.0.0/12';
26
        }
27
28 1
        return 'Internet';
29
    }
30
}
31