1
|
|
|
<?php |
2
|
|
|
namespace Workana\AsyncJobs\EventDispatching; |
3
|
|
|
|
4
|
|
|
use Exception; |
5
|
|
|
use ReflectionFunction; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Aggregate child of event exception |
9
|
|
|
* |
10
|
|
|
* @author Carlos Frutos <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class AggregateChildEventException extends Exception |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var AggregateRootEventException |
16
|
|
|
*/ |
17
|
|
|
protected $parent; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Callable |
21
|
|
|
*/ |
22
|
|
|
protected $listener; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $listenerName; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Throwable|Exception |
31
|
|
|
*/ |
32
|
|
|
protected $wrappedError; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var AggregateRootEventException $parent |
36
|
|
|
* @var Callable $listener |
37
|
|
|
* @var Exception|Throwable $wrappedError |
38
|
|
|
*/ |
39
|
|
|
public function __construct( |
40
|
|
|
AggregateRootEventException $parent, |
41
|
|
|
Callable $listener, |
42
|
|
|
$wrappedError |
43
|
|
|
) { |
44
|
|
|
$this->parent = $parent; |
45
|
|
|
$this->listener = $listener; |
46
|
|
|
$this->listenerName = $this->calculateListenerName($listener); |
47
|
|
|
$this->wrappedError = $wrappedError; |
48
|
|
|
|
49
|
|
|
parent::__construct(strtr('Failed event :eventName on listener :listenerName with message: :errorMessage', [ |
50
|
|
|
':eventName' => $this->parent->getEventName(), |
51
|
|
|
':listenerName' => $this->listenerName, |
52
|
|
|
':errorMessage' => $this->wrappedError->getMessage(), |
53
|
|
|
])); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Calculate listener name |
58
|
|
|
* |
59
|
|
|
* @param Callable $listener |
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
private function calculateListenerName(Callable $listener) |
64
|
|
|
{ |
65
|
|
|
if (is_array($listener)) { |
66
|
|
|
$class = is_object($listener[0]) ? get_class($listener[0]) : (string) $listener[0]; |
67
|
|
|
|
68
|
|
|
return implode('::', [$class, $listener[1]]); |
69
|
|
|
} elseif ($listener instanceof Closure) { |
|
|
|
|
70
|
|
|
$reflection = new ReflectionFunction($callable); |
|
|
|
|
71
|
|
|
|
72
|
|
|
return "[closure]#{$reflection->getFileName()}:{$reflection->getStartLine()}"; |
73
|
|
|
} elseif (is_string($listener)) { |
74
|
|
|
return $listener; |
75
|
|
|
} elseif (is_object($listener)) { |
76
|
|
|
$class = get_class($listener); |
|
|
|
|
77
|
|
|
|
78
|
|
|
return "[invokable]#{class}"; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getEventName() |
83
|
|
|
{ |
84
|
|
|
return $this->parent->getEventName(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getEvent() |
88
|
|
|
{ |
89
|
|
|
return $this->parent->getEvent(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getListener() |
93
|
|
|
{ |
94
|
|
|
return $this->listener; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function getListenerName() |
98
|
|
|
{ |
99
|
|
|
return $this->listenerName; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getWrappedError() |
103
|
|
|
{ |
104
|
|
|
return $this->wrappedError; |
105
|
|
|
} |
106
|
|
|
} |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.