Passed
Push — master ( 5bee03...81593c )
by Alexey
05:39 queued 11s
created

ConsoleLog   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 9
c 1
b 0
f 0
dl 0
loc 19
ccs 7
cts 10
cp 0.7
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A log() 0 6 4
A __construct() 0 8 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (c) Ne-Lexa
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 *
11
 * @see https://github.com/Ne-Lexa/google-play-scraper
12
 */
13
14
namespace Nelexa\GPlay\HttpClient;
15
16
use Psr\Log\AbstractLogger;
17
use Psr\Log\LogLevel;
18
19
class ConsoleLog extends AbstractLogger
20
{
21 2
    public function __construct()
22
    {
23 2
        if (!\defined('STDOUT')) {
24
            \define('STDOUT', fopen('php://stdout', 'wb'));
25
        }
26
27 2
        if (!\defined('STDERR')) {
28
            \define('STDERR', fopen('php://stderr', 'wb'));
29
        }
30
    }
31
32 60
    public function log($level, $message, array $context = []): void
33
    {
34 60
        $stream = LogLevel::DEBUG === $level || LogLevel::INFO === $level ? \STDOUT : \STDERR;
35 60
        fwrite($stream, '[' . strtoupper($level) . '] ' . $message . \PHP_EOL);
36 60
        if (!empty($context)) {
37
            fwrite($stream, var_export($context, true) . \PHP_EOL);
38
        }
39
    }
40
}
41