Logger   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A log() 0 3 2
A __construct() 0 3 1
A error() 0 3 1
1
<?php
2
3
namespace Sludio\HelperBundle\Script\Utils;
4
5
use Psr\Log\LoggerInterface;
6
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
7
8
class Logger
9
{
10
    protected $logger;
11
12
    /**
13
     * Constructor.
14
     *
15
     * @param LoggerInterface $logger
16
     *
17
     * @throws InvalidArgumentException
18
     */
19
    public function __construct(LoggerInterface $logger = null)
20
    {
21
        $this->logger = $logger;
22
    }
23
24
    public function error($command, $error)
25
    {
26
        $this->log($command, $error, 'error');
27
    }
28
29
    /**
30
     * Logs a command
31
     *
32
     * @param string      $command Ccommand
33
     * @param null|string $error   Error message or null
34
     * @param string      $type    Log type
35
     */
36
    public function log($command, $error = null, $type = 'info')
37
    {
38
        $this->logger->{(string)$type}($command.': '.strtoupper((string)$type).($error !== null ? ': '.(string)$error : ''));
39
    }
40
}
41