1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace Yiisoft\Yii\Debug\Collector; |
||||
6 | |||||
7 | use Yiisoft\Yii\Debug\Event\ProxyMethodCallEvent; |
||||
8 | |||||
9 | trait ProxyLogTrait |
||||
10 | { |
||||
11 | private ContainerProxyConfig $config; |
||||
12 | |||||
13 | protected function logProxy( |
||||
14 | string $service, |
||||
15 | 6 | object $instance, |
|||
16 | string $method, |
||||
17 | array $arguments, |
||||
18 | $result, |
||||
19 | float $timeStart |
||||
20 | ): void { |
||||
21 | $error = $this->getCurrentError(); |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
22 | $this->processLogData($arguments, $result, $error); |
||||
23 | 6 | ||||
24 | 6 | if ($this->config->getCollector() !== null) { |
|||
25 | $this->logToCollector($service, $instance, $method, $arguments, $result, $error, $timeStart); |
||||
26 | 6 | } |
|||
27 | 6 | ||||
28 | if ($this->config->getDispatcher() !== null) { |
||||
29 | $this->logToEvent($service, $instance, $method, $arguments, $result, $error, $timeStart); |
||||
30 | 6 | } |
|||
31 | 6 | } |
|||
32 | |||||
33 | private function processLogData(array &$arguments, &$result, ?object &$error): void |
||||
34 | { |
||||
35 | 6 | if (!($this->config->getLogLevel() & ContainerInterfaceProxy::LOG_ARGUMENTS)) { |
|||
36 | $arguments = null; |
||||
37 | 6 | } |
|||
38 | |||||
39 | if (!($this->config->getLogLevel() & ContainerInterfaceProxy::LOG_RESULT)) { |
||||
40 | $result = null; |
||||
41 | 6 | } |
|||
42 | 6 | ||||
43 | if (!($this->config->getLogLevel() & ContainerInterfaceProxy::LOG_ERROR)) { |
||||
44 | $error = null; |
||||
45 | 6 | } |
|||
46 | 6 | } |
|||
47 | |||||
48 | private function logToCollector( |
||||
49 | string $service, |
||||
50 | 6 | object $instance, |
|||
51 | string $method, |
||||
52 | ?array $arguments, |
||||
53 | $result, |
||||
54 | ?object $error, |
||||
55 | float $timeStart |
||||
56 | ): void { |
||||
57 | $this->config->getCollector()?->collect( |
||||
58 | $service, |
||||
59 | 6 | $instance::class, |
|||
60 | $method, |
||||
61 | 6 | $arguments, |
|||
62 | $result, |
||||
63 | $this->getCurrentResultStatus(), |
||||
64 | $error, |
||||
65 | 6 | $timeStart, |
|||
66 | microtime(true), |
||||
0 ignored issues
–
show
It seems like
microtime(true) can also be of type string ; however, parameter $timeEnd of Yiisoft\Yii\Debug\Collec...iceCollector::collect() does only seem to accept double , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
67 | ); |
||||
68 | 6 | } |
|||
69 | |||||
70 | private function logToEvent( |
||||
71 | string $service, |
||||
72 | 6 | object $instance, |
|||
73 | string $method, |
||||
74 | ?array $arguments, |
||||
75 | $result, |
||||
76 | ?object $error, |
||||
77 | float $timeStart |
||||
78 | ): void { |
||||
79 | $this->config->getDispatcher()?->dispatch( |
||||
80 | new ProxyMethodCallEvent( |
||||
81 | 6 | $service, |
|||
82 | 6 | $instance::class, |
|||
83 | $method, |
||||
84 | 6 | $arguments, |
|||
85 | $result, |
||||
86 | $this->getCurrentResultStatus(), |
||||
87 | $error, |
||||
88 | 6 | $timeStart, |
|||
89 | microtime(true), |
||||
0 ignored issues
–
show
It seems like
microtime(true) can also be of type string ; however, parameter $timeEnd of Yiisoft\Yii\Debug\Event\...allEvent::__construct() does only seem to accept double , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
90 | ) |
||||
91 | 6 | ); |
|||
92 | } |
||||
93 | |||||
94 | private function getCurrentResultStatus(): string |
||||
95 | { |
||||
96 | 6 | if (!$this->hasCurrentError()) { |
|||
0 ignored issues
–
show
It seems like
hasCurrentError() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
97 | return 'success'; |
||||
98 | 6 | } |
|||
99 | 6 | ||||
100 | return 'failed'; |
||||
101 | } |
||||
102 | } |
||||
103 |