Validator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 28
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateIp() 0 20 3
1
<?php
2
3
namespace Jodn14\Models;
4
5
/**
6
 * Model for validating an ip address
7
 *
8
 */
9
class Validator
10
{
11
    /**
12
     * calls ipstack with ip parameter
13
     *
14
     * @param string ip-address
0 ignored issues
show
Documentation Bug introduced by
The doc comment ip-address at position 0 could not be parsed: Unknown type name 'ip-address' at position 0 in ip-address.
Loading history...
15
     * @return array
16
     */
17 7
    public static function validateIp($ipAddress) : array
18
    {
19
        //valideringslogik
20 7
        $hostname = "undefined host";
21
22 7
        if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
23 1
            $result = $ipAddress . " is a valid IPv6 Address.";
24 1
            $hostname = gethostbyaddr($ipAddress);
25 7
        } else if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
26 7
            $result = $ipAddress . " is a valid IPv4 Address.";
27 7
            $hostname = gethostbyaddr($ipAddress);
28
        } else {
29 7
            $result = $ipAddress . " is not a valid IP Address.";
30
        }
31
        $data = [
32 7
            "result" => $result,
33 7
            "hostname" => $hostname
34
        ];
35
36 7
        return $data;
37
    }
38
}
39