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

TypeConstraint::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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