Completed
Push — bridge-refactor ( 54fa11 )
by Sullivan
05:53
created

ZipCode::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 3
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 9.4285
1
<?php
2
3
namespace SLLH\IsoCodesValidator\Constraints;
4
5
use IsoCodes;
6
use SLLH\IsoCodesValidator\AbstractConstraint;
7
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
8
9
/**
10
 * @Annotation
11
 * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
12
 *
13
 * @author Sullivan Senechal <[email protected]>
14
 */
15
final class ZipCode extends AbstractConstraint
16
{
17
    const ALL           = 'all';
18
19
    public $country = self::ALL;
20
21
    public $message = 'This value is not a valid ZIP code.';
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function __construct($options = null)
27
    {
28
        parent::__construct($options);
29
30
        if ($this->country != self::ALL && !in_array($this->country, IsoCodes\ZipCode::getAvailableCountries())) {
31
            throw new ConstraintDefinitionException(sprintf(
32
                'The option "country" must be one of "%s" or "all"',
33
                implode('", "', IsoCodes\ZipCode::getAvailableCountries())
34
            ));
35
        }
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getIsoCodesVersion()
42
    {
43
        return '1.0.0';
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getIsoCodesClass()
50
    {
51
        return IsoCodes\ZipCode::class;
52
    }
53
}
54