UnresolvableArgumentException::getFunctionName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the rybakit/arguments-resolver package.
7
 *
8
 * (c) Eugene Leonovich <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace ArgumentsResolver;
15
16
class UnresolvableArgumentException extends \InvalidArgumentException
17
{
18 7
    public static function fromParameter(\ReflectionParameter $parameter) : self
19
    {
20 7
        return new self(\sprintf(
21 7
            'Unable to resolve argument $%s (#%d) of %s.',
22 7
            $parameter->name,
23 7
            $parameter->getPosition(),
24 7
            self::getFunctionName($parameter->getDeclaringFunction())
25
        ));
26
    }
27
28 7
    private static function getFunctionName(\ReflectionFunctionAbstract $reflection) : string
29
    {
30 7
        $name = $reflection->name.'()';
31
32 7
        if ($reflection instanceof \ReflectionMethod) {
33 6
            $name = $reflection->getDeclaringClass()->name.'::'.$name;
34
        }
35
36 7
        return $name;
37
    }
38
}
39