Completed
Pull Request — master (#13)
by
unknown
07:00
created

Domain   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 19 6
A match() 0 4 1
1
<?php
2
3
namespace Whitelist\Definition;
4
5
/**
6
 * Represents a domain definition
7
 *
8
 * @author Sam Stenvall <[email protected]>
9
 * @copyright Copyright &copy; Sam Stenvall 2014-
10
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
11
 */
12
class Domain extends Definition
13
{
14
15
    public function validate()
16
    {
17
        // The domain name cannot be empty
18
        if (strlen($this->_definition) === 0) {
19
            return false;
20
        }
21
22
        // None of the parts in the domain name can contain invalid characters
23
        // or begin/end with a dash
24
        foreach (explode('.', $this->_definition) as $part) {
25
            if (! preg_match('/^[a-zA-Z0-9-\.]+$/', $part) ||
26
                substr($part, 0, 1) === '-' ||
27
                substr($part, -1) === '-') {
28
                return false;
29
            }
30
        }
31
32
        return true;
33
    }
34
35
    public function match($value)
36
    {
37
        return $this->_definition === $value;
38
    }
39
40
}
41