| Total Complexity | 4 | 
| Total Lines | 53 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | <?php | ||
| 10 | class Phone extends Regex | ||
| 11 | { | ||
| 12 | /** | ||
| 13 | * Base validation pattern which includes + char only, | ||
| 14 | * all other parts are built on the fly | ||
| 15 | */ | ||
| 16 | const VALIDATION_PATTERN = '/^\+(%s)$/'; | ||
| 17 | |||
| 18 | /** | ||
| 19 | * @var string | ||
| 20 | */ | ||
| 21 | public $message = 'Phone number format is not valid'; | ||
| 22 | |||
| 23 | /** | ||
| 24 | * @param mixed $options | ||
| 25 | * @return self | ||
| 26 | */ | ||
| 27 | public function __construct($options = null) | ||
| 28 |     { | ||
| 29 | $options['pattern'] = sprintf( | ||
| 30 | self::VALIDATION_PATTERN, | ||
| 31 | $this->buildPattern($this->getCountryPatterns()) | ||
| 32 | ); | ||
| 33 | parent::__construct($options); | ||
| 34 | } | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Build one regexp pattern from given list of patterns | ||
| 38 | * @param array $patterns | ||
| 39 | * @return string built regexp | ||
| 40 | */ | ||
| 41 | private function buildPattern(array $patterns) | ||
| 49 | } | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Regexp patterns by country | ||
| 53 | * IMPORTANT! | ||
| 54 | * DO NOT FORGET TO UPDATE REGULAR EXPRESSION VALIDATOR IN JAVASCRIPT! | ||
| 55 | * @return array | ||
| 56 | */ | ||
| 57 | private function getCountryPatterns() | ||
| 66 |