Passed
Pull Request — master (#129)
by Sergei
02:39
created

NotDetermineDefaultValueOfPhpInternalException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
dl 0
loc 25
c 1
b 0
f 0
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCallable() 0 11 2
A __construct() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Factory\Exception;
6
7
use ReflectionParameter;
8
9
final class NotDetermineDefaultValueOfPhpInternalException extends NotInstantiableException
10
{
11 1
    public function __construct(ReflectionParameter $parameter)
12
    {
13 1
        parent::__construct(
14 1
            sprintf(
15
                'Can not determine default value of parameter "%s" when instantinate "%s" ' .
16 1
                'because it is PHP internal. Please specify argument explicitly.',
17 1
                $parameter->getName(),
18 1
                $this->getCallable($parameter),
19
            )
20
        );
21 1
    }
22
23 1
    private function getCallable(ReflectionParameter $parameter): string
24
    {
25 1
        $callable = [];
26
27 1
        $class = $parameter->getDeclaringClass();
28 1
        if ($class !== null) {
29 1
            $callable[] = $class->getName();
30
        }
31 1
        $callable[] = $parameter->getDeclaringFunction()->getName() . '()';
32
33 1
        return implode('::', $callable);
34
    }
35
}
36