TerminalHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A isHandling() 0 4 1
1
<?php
2
3
/**
4
 * Phoole (PHP7.2+)
5
 *
6
 * @category  Library
7
 * @package   Phoole\Logger
8
 * @copyright Copyright (c) 2019 Hong Zhang
9
 */
10
declare(strict_types=1);
11
12
namespace Phoole\Logger\Handler;
13
14
use Phoole\Logger\Formatter\AnsiFormatter;
15
use Phoole\Logger\Entry\LogEntryInterface;
16
use Phoole\Logger\Formatter\FormatterInterface;
17
18
/**
19
 * log to a terminal
20
 *
21
 * @package Phoole\Logger
22
 */
23
class TerminalHandler extends StreamHandler
24
{
25
    /**
26
     * @param  string|resource    $stream
27
     * @param  FormatterInterface $formatter
28
     */
29
    public function __construct(
30
        $stream = 'php://stderr',
31
        ?FormatterInterface $formatter = NULL
32
    ) {
33
        if (!in_array($stream, ['php://stderr', 'php://stdout'])) {
34
            throw new \LogicException("unknown stream");
35
        }
36
        parent::__construct($stream, $formatter ?? new AnsiFormatter());
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    protected function isHandling(LogEntryInterface $entry): bool
43
    {
44
        return 'cli' === php_sapi_name();
45
    }
46
}