Failed Conditions
Pull Request — new-parser-ast-metadata (#3)
by
unknown
01:53
created

PropertyMetadata::validateValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
ccs 4
cts 4
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;
6
7
use Doctrine\Annotations\Metadata\Constraint\Constraint;
8
use Doctrine\Annotations\Metadata\Constraint\ConstraintNotFulfilled;
9
10
final class PropertyMetadata
11
{
12
    /** @var string */
13
    private $name;
14
15
    /** @var Constraint */
16
    private $valueConstraint;
17
18 9
    public function __construct(string $name, Constraint $valueConstraint)
19
    {
20 9
        $this->name            = $name;
21 9
        $this->valueConstraint = $valueConstraint;
22 9
    }
23
24 8
    public function getName() : string
25
    {
26 8
        return $this->name;
27
    }
28
29
    /**
30
     * @param mixed $value
31
     *
32
     * @throws InvalidPropertyValue
33
     */
34 6
    public function validateValue($value) : void
35
    {
36
        try {
37 6
            $this->valueConstraint->validate($value);
38 1
        } catch (ConstraintNotFulfilled $exception) {
39 1
            throw InvalidPropertyValue::new($this, $exception);
40
        }
41 5
    }
42
}
43