Passed
Pull Request — master (#105)
by Evgeniy
08:08 queued 04:03
created

ParameterService::getName()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
nc 4
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI\Reflection;
6
7
use ReflectionParameter;
8
9
class ParameterService
10
{
11
    /**
12
     * @param ReflectionParameter $parameter
13
     * @param array<string> $annotations
14
     * @return string
15
     */
16 6
    public function getName(ReflectionParameter $parameter, array $annotations): string
17
    {
18 6
        $result = $parameter->getClass() === null ? $parameter->name : $parameter->getClass()->name;
19 6
        if (array_key_exists($result, $annotations)) {
20 3
            $result = $annotations[$result];
21
        }
22 6
        return $result;
23
    }
24
}
25