ResolverVisitorMethod   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A resolveVisiteeClass() 0 14 4
A isVisiteeParameter() 0 5 2
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Visitor;
12
13
/**
14
 * Resolver Visitor Method class.
15
 *
16
 * @author Karel Osorio Ramírez <[email protected]>
17
 */
18
class ResolverVisitorMethod implements ResolverVisitorMethodInterface
19
{
20
    /**
21
     * @var string
22
     */
23
    protected $prefix;
24
25
    /**
26
     * @param string $prefix
27
     */
28
    public function __construct($prefix = 'visit')
29
    {
30
        $this->prefix = empty($prefix) ? 'visit' : $prefix;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function resolveVisiteeClass(\ReflectionMethod $method)
37
    {
38
        $parameters = $method->getParameters();
39
        if (empty($parameters)) {
40
            return;
41
        }
42
43
        /** @var \ReflectionParameter $visiteeParameter */
44
        $visiteeParameter = $parameters[0];
45
46
        return ($this->isVisiteeParameter($visiteeParameter) &&
47
            $method->getName() === $this->prefix.$visiteeParameter->getClass()->getShortName()) ?
0 ignored issues
show
Bug introduced by
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
48
            $visiteeParameter->getClass() : null;
49
    }
50
51
    /**
52
     * @param \ReflectionParameter $visiteeParameter
53
     *
54
     * @return bool
55
     */
56
    private function isVisiteeParameter(\ReflectionParameter $visiteeParameter)
57
    {
58
        return $visiteeParameter->getClass() !== null &&
59
            $visiteeParameter->getClass()->implementsInterface(VisiteeInterface::class);
60
    }
61
}
62