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

Validator::isValid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
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