Completed
Push — not-exists ( 0b7a0f )
by Sullivan
05:13 queued 02:01
created

Isbn   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 41
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultOption() 0 4 1
A __construct() 0 8 3
A getIsoCodesVersion() 0 4 1
A getIsoCodesClass() 0 4 1
1
<?php
2
3
namespace SLLH\IsoCodesValidator\Constraints;
4
5
use SLLH\IsoCodesValidator\AbstractConstraint;
6
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
7
8
/**
9
 * @Annotation
10
 * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
11
 *
12
 * @author Sullivan Senechal <[email protected]>
13
 */
14
final class Isbn extends AbstractConstraint
15
{
16
    public $message = 'This value is not a valid ISBN.';
17
    public $type = null;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function __construct($options = null)
23
    {
24
        parent::__construct($options);
25
26
        if ($this->type !== null && !in_array($this->type, [10, 13])) {
27
            throw new ConstraintDefinitionException('The option "type" must be 10 or 13');
28
        }
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getDefaultOption()
35
    {
36
        return 'type';
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getIsoCodesVersion()
43
    {
44
        return '1.2.0';
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getIsoCodesClass()
51
    {
52
        return \IsoCodes\Isbn::class;
53
    }
54
}
55