Completed
Push — master ( 887cf7...2ea773 )
by Emily
02:13
created

ReflectionMethodFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 50
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromName() 0 7 1
A build() 0 11 1
1
<?php
2
/**
3
 * This file is part of the Composite Utils package.
4
 *
5
 * (c) Emily Shepherd <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the
8
 * LICENSE.md file that was distributed with this source code.
9
 *
10
 * @package spaark/composite-utils
11
 * @author Emily Shepherd <[email protected]>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Factory\Reflection;
16
17
use Spaark\CompositeUtils\Model\Reflection\ReflectionComposite;
18
use Spaark\CompositeUtils\Model\Reflection\ReflectionMethod;
19
use \ReflectionMethod as PHPNativeReflectionMethod;
20
21
/**
22
 * Builds a ReflectionMethod for a given method and optionally links
23
 * this to a parent ReflectionComposite
24
 */
25
class ReflectionMethodFactory extends ReflectorFactory
26
{
27
    const REFLECTION_OBJECT = ReflectionMethod::class;
28
29
    /**
30
     * @var PHPNativeReflectionMethod
31
     */
32
    protected $reflector;
33
34
    /**
35
     * @var ReflectionMethod
36
     */
37
    protected $object;
38
39
    /**
40
     * Returns a new ReflectionMethodFactory using the given class and
41
     * method names
42
     *
43
     * @param string $class The classname of the method
44
     * @param string $method The method to reflect
45
     * @return ReflectionMethodFactory
46
     */
47
    public static function fromName(string $class, string $method)
48
    {
49
        return new static(new PHPNativeReflectionMethod
50
        (
51
            $class, $method
52
        ));
53
    }
54
55
    /**
56
     * Builds the ReflectionMethod from the provided parameters,
57
     * optionally linking to a parent ReflectionComposite
58
     *
59
     * @param ReflectionComposite $parent The reflector for the class
60
     *     this method belongs to
61
     * @return ReflectionMethod
62
     */
63
    public function build(?ReflectionComposite $parent = null)
64
    {
65
        $this->accessor->setRawValue('owner', $parent);
66
        $this->accessor->setRawValue
67
        (
68
            'name',
69
            $this->reflector->getName()
0 ignored issues
show
Bug introduced by
Consider using $this->reflector->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
70
        );
71
72
        return $this->object;
73
    }
74
}
75
76