PropertyMapping::setValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Maiorano\ObjectHydrator\Mappings;
4
5
use JetBrains\PhpStorm\Pure;
6
use Maiorano\ObjectHydrator\Attributes\HydrationKey;
7
use ReflectionNamedType;
8
use ReflectionProperty;
9
10
class PropertyMapping implements HydrationMappingInterface
11
{
12
    /**
13
     * @var ReflectionProperty
14
     */
15
    private ReflectionProperty $reflector;
16
    /**
17
     * @var HydrationKey
18
     */
19
    private HydrationKey $key;
20
21
    /**
22
     * @param ReflectionProperty $reflector
23
     * @param HydrationKey       $key
24
     */
25 16
    public function __construct(ReflectionProperty $reflector, HydrationKey $key)
26
    {
27 16
        $this->reflector = $reflector;
28 16
        $this->key = $key;
29 16
    }
30
31
    /**
32
     * @return string
33
     */
34 11
    #[Pure]
35
    public function getKey(): string
36
    {
37 11
        return $this->key->getKey();
38
    }
39
40
    /**
41
     * @return ?ReflectionNamedType
42
     */
43 9
    #[Pure]
44
    public function getType(): ?ReflectionNamedType
45
    {
46 9
        return $this->reflector->getType();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->reflector->getType() could return the type ReflectionType which includes types incompatible with the type-hinted return ReflectionNamedType|null. Consider adding an additional type-check to rule them out.
Loading history...
47
    }
48
49
    /**
50
     * @param object $object
51
     * @param mixed  $value
52
     *
53
     * @return void
54
     */
55 7
    public function setValue(object $object, mixed $value): void
56
    {
57 7
        $this->reflector->setValue($object, $value);
58 7
    }
59
}
60