IPAddress::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Domain\Web;
13
14
/**
15
 * IPAddress class.
16
 *
17
 * @author Ivannis Suárez Jerez <[email protected]>
18
 */
19
class IPAddress extends Host
20
{
21
    /**
22
     * @param string $ip
23
     *
24
     * @throws \InvalidArgumentException
25
     */
26
    public function __construct($ip)
27
    {
28
        $filteredValue = filter_var($ip, FILTER_VALIDATE_IP);
29
        if ($filteredValue === false) {
30
            throw new \InvalidArgumentException(sprintf(
31
                'Argument "%s" is invalid. Allowed types for argument are "ip address".',
32
                $ip
33
            ));
34
        }
35
36
        parent::__construct((string) $ip);
37
    }
38
}
39