Completed
Pull Request — 2.x (#349)
by Alexander
02:20
created

InterceptedMethodGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 45
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 34 5
1
<?php
2
declare(strict_types=1);
3
/*
4
 * Go! AOP framework
5
 *
6
 * @copyright Copyright 2018, Lisachenko Alexander <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Go\Proxy\Part;
13
14
use ReflectionMethod;
15
use Zend\Code\Generator\DocBlockGenerator;
16
use Zend\Code\Generator\MethodGenerator;
17
use Zend\Code\Reflection\DocBlockReflection;
18
19
/**
20
 * Prepares the definition of intercepted method
21
 */
22
final class InterceptedMethodGenerator extends MethodGenerator
23
{
24
25
    /**
26
     * InterceptedMethod constructor.
27
     *
28
     * @param ReflectionMethod $reflectionMethod Instance of original method
29
     * @param string           $body             Method body
30
     * @param bool             $useTypeWidening  Should generator use parameter widening for PHP>=7.2
31
     */
32 16
    public function __construct(ReflectionMethod $reflectionMethod, string $body, bool $useTypeWidening = false)
33
    {
34 16
        parent::__construct($reflectionMethod->getName());
35
36 16
        $declaringClass = $reflectionMethod->getDeclaringClass();
37
38 16
        if ($reflectionMethod->hasReturnType()) {
39 1
            $this->setReturnType((string) $reflectionMethod->getReturnType());
40
        }
41
42 16
        if ($reflectionMethod->getDocComment()) {
43 3
            $reflectionDocBlock = new DocBlockReflection($reflectionMethod->getDocComment());
44 3
            $this->setDocBlock(DocBlockGenerator::fromReflection($reflectionDocBlock));
45
        }
46
47 16
        $this->setFinal($reflectionMethod->isFinal());
48
49 16
        if ($reflectionMethod->isPrivate()) {
50 1
            $this->setVisibility(self::VISIBILITY_PRIVATE);
51 15
        } elseif ($reflectionMethod->isProtected()) {
52 4
            $this->setVisibility(self::VISIBILITY_PROTECTED);
53
        } else {
54 12
            $this->setVisibility(self::VISIBILITY_PUBLIC);
55
        }
56
57 16
        $this->setInterface($declaringClass->isInterface());
58 16
        $this->setStatic($reflectionMethod->isStatic());
59 16
        $this->setReturnsReference($reflectionMethod->returnsReference());
60 16
        $this->setName($reflectionMethod->getName());
61
62 16
        $parameterList = new FunctionParameterList($reflectionMethod, $useTypeWidening);
63 16
        $this->setParameters($parameterList->getGeneratedParameters());
64 16
        $this->setBody($body);
65 16
    }
66
}
67