ReflectionFunctionFactory::export()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
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