IpVN::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
rs 9.6666
cc 4
nc 4
nop 1
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/symfony-validation
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [MIT](http://www.opensource.org/licenses/MIT)
6
 */
7
8
namespace PHPViet\Symfony\Validation\Constraints;
9
10
use Symfony\Component\Validator\Constraint;
11
use PHPViet\Validation\Rules\IpVN as BaseIpVN;
12
13
/**
14
 * @Annotation
15
 *
16
 * @author Vuong Minh <[email protected]>
17
 * @since 1.0.0
18
 */
19
class IpVN extends Constraint
20
{
21
    const IPV4 = BaseIpVN::IPV4;
22
23
    const IPV6 = BaseIpVN::IPV6;
24
25
    const IP_VN_ERROR = 'a21abd13-9fc6-4319-a07a-9dfdc0b33719';
26
27
    const IPV4_VN_ERROR = '6b162d27-d99e-4c4c-aadd-179a8b37ebc8';
28
29
    const IPV6_VN_ERROR = '1c417ab3-734c-4694-a52e-af4bcfc8dd4f';
30
31
    protected static $errorNames = [
32
        self::IP_VN_ERROR => 'IP_VN_ERROR',
33
        self::IPV4_VN_ERROR => 'IPV4_VN_ERROR',
34
        self::IPV6_VN_ERROR => 'IPV6_VN_ERROR',
35
    ];
36
37
    public $message;
38
39
    public $version;
40
41
    public function __construct($options = null)
42
    {
43
        parent::__construct($options);
44
45
        if (null === $this->message) {
46
            switch ($this->version) {
47
                case self::IPV4:
48
                    $this->message = 'This is not a valid Vietnam ipv4.';
49
                    break;
50
                case self::IPV6:
51
                    $this->message = 'This is not a valid Vietnam ipv6.';
52
                    break;
53
                default:
54
                    $this->message = 'This is not a valid Vietnam ip.';
55
                    break;
56
            }
57
        }
58
    }
59
}
60