CommandHandlerLogger::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 *  This file is part of the Simple S3 package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 */
11
12
namespace Matecat\SimpleS3\Components\Logger;
13
14
use Exception;
15
use Matecat\SimpleS3\Commands\CommandHandler;
16
use Psr\Log\LoggerInterface;
17
18
class CommandHandlerLogger
19
{
20
    /**
21
     * @var LoggerInterface
22
     */
23
    protected LoggerInterface $logger;
24
25
    /**
26
     * Logger constructor.
27
     *
28
     * @param LoggerInterface $logger
29
     */
30 36
    public function __construct(LoggerInterface $logger)
31
    {
32 36
        $this->logger = $logger;
33
    }
34
35
    /**
36
     * @param CommandHandler $commandHandler
37
     * @param string         $message
38
     * @param string         $level
39
     */
40 32
    public function log(CommandHandler $commandHandler, string $message, string $level = 'info'): void
41
    {
42 32
        $msg = '[' . get_class($commandHandler) . '] ' . $message;
43 32
        $this->logger->{$level}($msg);
44
    }
45
46
    /**
47
     * @param Exception $exception
48
     *
49
     * @return bool
50
     */
51
    public function logExceptionAndReturnFalse(Exception $exception): bool
52
    {
53
        $this->logger->error($exception->getMessage());
54
55
        return false;
56
    }
57
}
58