Completed
Push — master ( 326300...0375a4 )
by Vasil
02:28
created

Validator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 7 2
1
<?php
2
3
namespace VasilDakov\Postcode;
4
5
/**
6
 * Class Validator
7
 * @author Vasil Dakov <[email protected]>
8
 */
9
class Validator implements ValidatorInterface {
10
11
    /**
12
     * Official gov.uk postcode regular expression
13
     */
14
    const POSTCODE = "/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2})$/";
15
16
    /**
17
     * @param  string  $value
18
     * @return boolean
19
     */
20
    public function isValid($value)
21
    {
22
        if (!\preg_match(self::POSTCODE, $value)) {
23
            return false;
24
        }
25
        return true;
26
    }
27
}
28