IPCIDR   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 17
c 2
b 1
f 0
dl 0
loc 36
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 16 3
A match() 0 10 2
1
<?php
2
3
namespace Whitelist\Definition;
4
5
use Exception;
6
use IpUtils\Expression\ExpressionInterface;
7
use IpUtils\Expression\Subnet;
8
use IpUtils\Factory;
9
10
/**
11
 * Represents a CIDR notation
12
 *
13
 * @author Sam Stenvall <[email protected]>
14
 * @copyright Copyright &copy; Sam Stenvall 2014-
15
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
16
 */
17
abstract class IPCIDR extends Definition
18
{
19
20
    /**
21
     * @var ExpressionInterface
22
     */
23
    protected $_subnet;
24
25
    public function validate()
26
    {
27
        try {
28
            $this->_subnet = Factory::getExpression($this->_definition);
29
30
            // Check that we got a subnet expression and not something else
31
            if (! $this->_subnet instanceof Subnet) {
32
                return false;
33
            }
34
        } catch (Exception $e) {
35
            unset($e);
36
37
            return false;
38
        }
39
40
        return true;
41
    }
42
43
    public function match($value)
44
    {
45
        try {
46
            $address = Factory::getAddress($value);
47
48
            return $this->_subnet->matches($address);
49
        } catch (Exception $e) {
50
            unset($e);
51
52
            return false;
53
        }
54
    }
55
56
}
57