Completed
Push — master ( 421ba0...8914c9 )
by Sullivan
03:09
created

ZipCode::getIsoCodesClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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