GetMethodReplacement::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 13
nc 1
nop 1
1
<?php
2
3
namespace Isolate\LazyObjects\Proxy\Adapter\OcramiusProxyManager\MethodGenerator;
4
5
use ProxyManager\Generator\MethodGenerator;
6
use ProxyManager\Generator\ParameterGenerator;
7
use Zend\Code\Generator\PropertyGenerator;
8
9 View Code Duplication
class GetMethodReplacement extends MethodGenerator
0 ignored issues
show
Duplication introduced by
This class 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...
10
{
11
    /**
12
     * Constructor
13
     */
14
    public function __construct(PropertyGenerator $methodReplacementsProperty)
15
    {
16
        parent::__construct('getMethodReplacement');
17
        $methodReplacementsProperty  = $methodReplacementsProperty->getName();
18
        $this->setVisibility(self::VISIBILITY_PRIVATE);
19
20
        $this->setParameter(new ParameterGenerator('methodName'));
21
22
        $body =
23
              "foreach (\$this->$methodReplacementsProperty as \$replacementDefinition) {\n"
24
            . "    if (\$replacementDefinition->getMethod()->isEqualTo(\$methodName)) {\n"
25
            . "         return \$replacementDefinition;\n"
26
            . "    }\n"
27
            . "}\n\n"
28
            . "throw new \\RuntimeException(sprintf(\"Method replacement for %s does not exists.\", \$methodName));\n";
29
30
        $this->setBody($body);
31
    }
32
}
33