EchoLogger::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the PHALCON-EXT package.
5
 *
6
 * (c) Jitendra Adhikari <[email protected]>
7
 *     <https://github.com/adhocore>
8
 *
9
 * Licensed under MIT license.
10
 */
11
12
namespace PhalconExt\Logger;
13
14
use Phalcon\Logger\Adapter as LoggerAdapter;
0 ignored issues
show
Bug introduced by
The type Phalcon\Logger\Adapter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Phalcon\Logger\Formatter\Line as LineFormatter;
0 ignored issues
show
Bug introduced by
The type Phalcon\Logger\Formatter\Line was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
/**
18
 * Echo logger targeted for CLI environment.
19
 *
20
 * @author  Jitendra Adhikari <[email protected]>
21
 * @license MIT
22
 *
23
 * @link    https://github.com/adhocore/phalcon-ext
24
 */
25
class EchoLogger extends LoggerAdapter
26
{
27
    /** @var array */
28
    protected $config;
29
30
    public function __construct(array $config)
31
    {
32
        $this->config = $config;
33
34
        if ($config['level'] ?? null) {
35
            $this->setLogLevel($config['level']);
36
        }
37
    }
38
39
    /**
40
     * Echoes the log message as it is in CLI!
41
     */
42
    protected function logInternal(string $message, int $type, int $time, array $context)
43
    {
44
        echo $this->getFormatter()->format($message, $type, $time, $context);
45
    }
46
47
    /**
48
     * Gets a plain line formatter with configured format.
49
     *
50
     * @return LineFormatter
51
     */
52
    public function getFormatter(): LineFormatter
53
    {
54
        if (!$this->_formatter) {
55
            $this->_formatter = new LineFormatter(
0 ignored issues
show
Bug Best Practice introduced by
The property _formatter does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
56
                $this->config['format'] ?? '[%type%][%date%] %message%',
57
                $this->config['date_format'] ?? 'Y-m-d H:i:s'
58
            );
59
        }
60
61
        return $this->_formatter;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function close()
68
    {
69
        return true;
70
    }
71
}
72