yiisoft /
yii-debug
| 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 | mixed $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 | /** |
||||
| 34 | * @psalm-param-out array|null $arguments |
||||
| 35 | 6 | */ |
|||
| 36 | private function processLogData(array &$arguments, mixed &$result, ?object &$error): void |
||||
| 37 | 6 | { |
|||
| 38 | if (!($this->config->getLogLevel() & ContainerInterfaceProxy::LOG_ARGUMENTS)) { |
||||
| 39 | $arguments = null; |
||||
| 40 | } |
||||
| 41 | 6 | ||||
| 42 | 6 | if (!($this->config->getLogLevel() & ContainerInterfaceProxy::LOG_RESULT)) { |
|||
| 43 | $result = null; |
||||
| 44 | } |
||||
| 45 | 6 | ||||
| 46 | 6 | if (!($this->config->getLogLevel() & ContainerInterfaceProxy::LOG_ERROR)) { |
|||
| 47 | $error = null; |
||||
| 48 | } |
||||
| 49 | } |
||||
| 50 | 6 | ||||
| 51 | private function logToCollector( |
||||
| 52 | string $service, |
||||
| 53 | object $instance, |
||||
| 54 | string $method, |
||||
| 55 | ?array $arguments, |
||||
| 56 | mixed $result, |
||||
| 57 | ?object $error, |
||||
| 58 | float $timeStart |
||||
| 59 | 6 | ): void { |
|||
| 60 | $this->config->getCollector()?->collect( |
||||
| 61 | 6 | $service, |
|||
| 62 | $instance::class, |
||||
| 63 | $method, |
||||
| 64 | $arguments, |
||||
| 65 | 6 | $result, |
|||
| 66 | $this->getCurrentResultStatus(), |
||||
| 67 | $error, |
||||
| 68 | 6 | $timeStart, |
|||
| 69 | 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...
|
|||||
| 70 | ); |
||||
| 71 | } |
||||
| 72 | 6 | ||||
| 73 | private function logToEvent( |
||||
| 74 | string $service, |
||||
| 75 | object $instance, |
||||
| 76 | string $method, |
||||
| 77 | ?array $arguments, |
||||
| 78 | mixed $result, |
||||
| 79 | ?object $error, |
||||
| 80 | float $timeStart |
||||
| 81 | 6 | ): void { |
|||
| 82 | 6 | $this->config->getDispatcher()?->dispatch( |
|||
| 83 | new ProxyMethodCallEvent( |
||||
| 84 | 6 | $service, |
|||
| 85 | $instance::class, |
||||
| 86 | $method, |
||||
| 87 | $arguments, |
||||
| 88 | 6 | $result, |
|||
| 89 | $this->getCurrentResultStatus(), |
||||
| 90 | $error, |
||||
| 91 | 6 | $timeStart, |
|||
| 92 | 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...
|
|||||
| 93 | ) |
||||
| 94 | ); |
||||
| 95 | } |
||||
| 96 | 6 | ||||
| 97 | private function getCurrentResultStatus(): string |
||||
| 98 | 6 | { |
|||
| 99 | 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...
|
|||||
| 100 | return 'success'; |
||||
| 101 | } |
||||
| 102 | 1 | ||||
| 103 | return 'failed'; |
||||
| 104 | } |
||||
| 105 | } |
||||
| 106 |