ClassGeneratorUtils::addMethodIfNotFinal()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 6
cts 6
cp 1
rs 9.7666
c 0
b 0
f 0
cc 3
nc 2
nop 3
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\Generator\Util;
6
7
use Laminas\Code\Generator\ClassGenerator;
8
use Laminas\Code\Generator\MethodGenerator;
9
use ReflectionClass;
10
11
/**
12
 * Util class to help to generate code
13
 */
14
final class ClassGeneratorUtils
15
{
16
    public static function addMethodIfNotFinal(
17 2
        ReflectionClass $originalClass,
18
        ClassGenerator $classGenerator,
19
        MethodGenerator $generatedMethod
20
    ) : bool {
21
        $methodName = $generatedMethod->getName();
22 2
23
        if ($originalClass->hasMethod($methodName) && $originalClass->getMethod($methodName)->isFinal()) {
24 2
            return false;
25 1
        }
26
27
        $classGenerator->addMethodFromGenerator($generatedMethod);
28 1
29
        return true;
30 1
    }
31
}
32