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

ConsoleLog::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 8
ccs 3
cts 5
cp 0.6
rs 10
cc 3
nc 4
nop 0
crap 3.576
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