From 3b3bf4665fe9c49f789c29a7d899d9b8f7dbf9bc Mon Sep 17 00:00:00 2001 From: Andru Cherny Date: Fri, 4 Jun 2021 18:22:02 +0300 Subject: [PATCH] add trigger_error when logger not set --- .docker/app_test/Dockerfile | 1 - src/Utils/LoggerTrait.php | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.docker/app_test/Dockerfile b/.docker/app_test/Dockerfile index a275da0..253a38c 100644 --- a/.docker/app_test/Dockerfile +++ b/.docker/app_test/Dockerfile @@ -13,5 +13,4 @@ COPY . /packages/ValueObject WORKDIR /packages/ValueObject RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer -RUN composer -vvv global require hirak/prestissimo RUN composer install diff --git a/src/Utils/LoggerTrait.php b/src/Utils/LoggerTrait.php index 30995a1..1cf75e3 100644 --- a/src/Utils/LoggerTrait.php +++ b/src/Utils/LoggerTrait.php @@ -60,11 +60,15 @@ public function setLogger(LoggerInterface $logger): self * @param int $level * @param mixed[] $context * + * @SuppressWarnings(PHPMD.ErrorControlOperator) + * * @return $this */ public function logMessage(string $message, int $level, array $context = []): self { if (!$this->logger instanceof LoggerInterface) { + @trigger_error('Logger not set for class:'.get_class($this), E_USER_WARNING); + return $this; } @@ -105,11 +109,15 @@ public function logMessage(string $message, int $level, array $context = []): se * @param int $level * @param string $message The error message to log * + * @SuppressWarnings(PHPMD.ErrorControlOperator) + * * @return $this */ public function logException(Throwable $exception, int $level, string $message): self { if (!$this->logger instanceof LoggerInterface) { + @trigger_error('Logger not set for class:'.get_class($this), E_USER_WARNING); + return $this; }