Completed
Push — master ( 812d68...15b189 )
by Pieter
17s queued 10s
created

ReflectionLocalizedSetterMethod::getPriority()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace W2w\Lib\ApieObjectAccessNormalizer\Setters;
4
5
use ReflectionMethod;
6
use Symfony\Component\PropertyInfo\Type;
7
use W2w\Lib\ApieObjectAccessNormalizer\Interfaces\LocalizationAwareInterface;
8
use W2w\Lib\ApieObjectAccessNormalizer\TypeUtils;
9
10
final class ReflectionLocalizedSetterMethod implements SetterInterface
11
{
12
    /**
13
     * @var ReflectionMethod
14
     */
15
    private $method;
16
17
    /**
18
     * @var callable
19
     */
20
    private $conversionFn;
21
22
    /**
23
     * @var LocalizationAwareInterface
24
     */
25
    private $localizationAware;
26
27
    public function __construct(ReflectionMethod $method, LocalizationAwareInterface $localizationAware, callable $conversionFn)
28
    {
29
        $this->method = $method;
30
        $this->localizationAware = $localizationAware;
31
        $this->conversionFn = $conversionFn;
32
    }
33
34
    public function getName(): string
35
    {
36
        return $this->method->getName();
37
    }
38
39
    public function setValue($object, $value)
40
    {
41
        return $this->method->invoke($object, call_user_func($this->conversionFn, $this->localizationAware->getContentLanguage()), $value);
42
    }
43
44
    public function getPriority(): int
45
    {
46
        return 4;
47
    }
48
49
    public function toType(): ?Type
50
    {
51
        return TypeUtils::convertMethodToType($this->method);
52
    }
53
}
54