Completed
Pull Request — master (#10)
by
unknown
01:00
created

IPCIDR   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

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