ReflectionMethodGetter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
c 1
b 0
f 1
dl 0
loc 40
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A toType() 0 3 1
A getValue() 0 3 1
A getPriority() 0 13 3
A getName() 0 3 1
1
<?php
2
3
4
namespace Apie\ObjectAccessNormalizer\Getters;
5
6
use Apie\ObjectAccessNormalizer\TypeUtils;
7
use ReflectionMethod;
8
use Symfony\Component\PropertyInfo\Type;
9
10
/**
11
 * Wrapper around a getter method.
12
 */
13
class ReflectionMethodGetter implements GetterInterface
14
{
15
    /**
16
     * @var ReflectionMethod
17
     */
18
    private $method;
19
20
    public function __construct(ReflectionMethod $method)
21
    {
22
        $this->method = $method;
23
    }
24
25
    public function getName(): string
26
    {
27
        return $this->method->getName();
28
    }
29
30
    public function getValue($object)
31
    {
32
        return $this->method->invoke($object);
33
    }
34
35
    public function getPriority(): int
36
    {
37
        $methodName = $this->method->getName();
38
        // getXXx method
39
        if (strpos($methodName, 'get') === 0) {
40
            return 3;
41
        }
42
        // isXxx method
43
        if (strpos($methodName, 'is') === 0) {
44
            return 2;
45
        }
46
        // hasXxx Method
47
        return 1;
48
    }
49
50
    public function toType(): ?Type
51
    {
52
        return TypeUtils::convertMethodToType($this->method);
53
    }
54
}
55