ReflectionFunctionFactory   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 66
Duplicated Lines 15.15 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 13
c 0
b 0
f 0
lcom 1
cbo 0
dl 10
loc 66
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 3
A create() 0 4 1
A export() 0 4 1
A getClosure() 0 6 2
A invoke() 0 4 1
A invokeArgs() 0 10 2
A isDisabled() 0 4 1
A __toString() 0 4 1
A getReflector() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace DependencyInjection\Internal;
4
5
class ReflectionFunctionFactory implements ReflectionFactoryInterface
6
{
7
    /**
8
     * @var \ReflectionFunction
9
     */
10
    private $reflectionFunction;
11
12 View Code Duplication
    public function __construct($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
    {
14
        if (!is_string($name) && !is_a($name, 'Closure', true)) {
15
            throw Exception\ReflectionExceptionFactory::invalidArgument(
16
                sprintf("Parameter 1 of %s must be a string or instance of \\Closure", __METHOD__)
17
            );
18
        }
19
20
        $this->reflectionFunction = new \ReflectionFunction($name);
21
    }
22
23
    public static function create($name)
24
    {
25
        return new static($name);
26
    }
27
28
    public static function export($name, $return = false)
29
    {
30
        return \ReflectionFunction::export($name, $return);
31
    }
32
33
    public function getClosure()
34
    {
35
        $closure = $this->reflectionFunction->getClosure();
36
37
        return ($closure instanceof \Closure ? $closure : null);
38
    }
39
40
    public function invoke()
41
    {
42
        return call_user_func_array([$this->reflectionFunction, 'invoke'], func_get_args());
43
    }
44
45
    public function invokeArgs($args = [])
46
    {
47
        if (!is_array($args)) {
48
            throw Exception\ReflectionExceptionFactory::invalidArgument(
49
                sprintf("Parameter 1 of %s must be an array.", __METHOD__)
50
            );
51
        }
52
53
        return $this->reflectionFunction->invokeArgs($args);
54
    }
55
56
    public function isDisabled()
57
    {
58
        return $this->reflectionFunction->isDisabled();
59
    }
60
61
    public function __toString()
62
    {
63
        return (string)$this->reflectionFunction;
64
    }
65
66
    public function getReflector()
67
    {
68
        return $this->reflectionFunction;
69
    }
70
}
71