Passed
Push — trunk ( c1976e...a42427 )
by Christian
12:40 queued 13s
created

CustomerZipCode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMessage() 0 3 1
A getMessageRequired() 0 3 1
A __construct() 0 9 3
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Customer\Validation\Constraint;
4
5
use Symfony\Component\Validator\Constraint;
6
use Symfony\Component\Validator\Constraints\NotBlank;
7
8
/**
9
 * @Annotation
10
 * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
11
 */
12
class CustomerZipCode extends Constraint
13
{
14
    public const ZIP_CODE_INVALID = 'ZIP_CODE_INVALID';
15
16
    public ?string $countryId = null;
17
18
    public bool $caseSensitiveCheck = true;
19
20
    /**
21
     * @var array<string, string>
22
     */
23
    protected static $errorNames = [
24
        NotBlank::IS_BLANK_ERROR => 'IS_BLANK_ERROR',
25
        self::ZIP_CODE_INVALID => 'ZIP_CODE_INVALID',
26
    ];
27
28
    private string $message = 'This value is not a valid ZIP code for country {{ iso }}';
29
30
    private string $messageRequired = 'Postal code is required for that country';
31
32
    /**
33
     * @param mixed $options
34
     */
35
    public function __construct($options = null)
36
    {
37
        if ($options !== null && !\is_array($options)) {
38
            $options = [
39
                'countryId' => $options,
40
            ];
41
        }
42
43
        parent::__construct($options);
44
    }
45
46
    public function getMessageRequired(): string
47
    {
48
        return $this->messageRequired;
49
    }
50
51
    public function getMessage(): string
52
    {
53
        return $this->message;
54
    }
55
}
56