Passed
Pull Request — new-parser-ast-metadata (#3)
by
unknown
03:27
created

TypeConstraint   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 5
dl 0
loc 17
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 4 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Metadata\Constraint;
6
7
use Doctrine\Annotations\Metadata\Type\Type;
8
9
final class TypeConstraint implements Constraint
10
{
11
    /** @var Type */
12
    private $type;
13
14 14
    public function __construct(Type $type)
15
    {
16 14
        $this->type = $type;
17 14
    }
18
19
    /**
20
     * @param mixed $value
21
     */
22 11
    public function validate($value) : void
23
    {
24 11
        if (! $this->type->validate($value)) {
25 3
            throw InvalidType::new($this->type->describe(), $value);
26
        }
27 8
    }
28
}
29