1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace Venta\Container\Exception; |
4
|
|
|
|
5
|
|
|
use Interop\Container\Exception\ContainerException as ContainerExceptionInterface; |
6
|
|
|
use ReflectionFunctionAbstract; |
7
|
|
|
use ReflectionMethod; |
8
|
|
|
use ReflectionParameter; |
9
|
|
|
use RuntimeException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ArgumentResolverException |
13
|
|
|
* |
14
|
|
|
* @package Venta\Container\Exception |
15
|
|
|
*/ |
16
|
|
|
class ArgumentResolverException extends RuntimeException implements ContainerExceptionInterface |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var ReflectionFunctionAbstract |
21
|
|
|
*/ |
22
|
|
|
private $function; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ReflectionParameter |
26
|
|
|
*/ |
27
|
|
|
private $parameter; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* ArgumentResolveException constructor. |
31
|
|
|
* |
32
|
|
|
* @param ReflectionParameter $parameter |
33
|
|
|
* @param ReflectionFunctionAbstract $function |
34
|
|
|
* @param null $previous |
35
|
|
|
*/ |
36
|
3 |
|
public function __construct(ReflectionParameter $parameter, ReflectionFunctionAbstract $function, $previous = null) |
37
|
|
|
{ |
38
|
3 |
|
$this->parameter = $parameter; |
39
|
3 |
|
$this->function = $function; |
|
|
|
|
40
|
3 |
|
parent::__construct($this->createMessage(), 0, $previous); |
41
|
3 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return ReflectionFunctionAbstract |
45
|
|
|
*/ |
46
|
1 |
|
public function getFunction(): ReflectionFunctionAbstract |
47
|
|
|
{ |
48
|
1 |
|
return $this->function; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return ReflectionParameter |
53
|
|
|
*/ |
54
|
1 |
|
public function getParameter(): ReflectionParameter |
55
|
|
|
{ |
56
|
1 |
|
return $this->parameter; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
3 |
|
protected function createMessage(): string |
63
|
|
|
{ |
64
|
3 |
|
return sprintf( |
65
|
3 |
|
'Unable to resolve parameter "%s" value for "%s" %s.', |
66
|
3 |
|
$this->parameter->getName(), |
67
|
3 |
|
$this->function->getName(), |
68
|
3 |
|
$this->function instanceof ReflectionMethod ? 'method' : 'function' |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.