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

PropertyMetadata::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

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 1
nc 1
nop 2
crap 1
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