InMemoryLogger::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Volan;
4
5
use Psr\Log\LoggerInterface;
6
7
class InMemoryLogger implements LoggerInterface
8
{
9
10
    /**
11
     * @var null|resource
12
     */
13
    protected $stream = null;
14
15
    public function __construct()
16
    {
17
        $filename = "php://memory";
18
19
        $fp = fopen($filename, "w+b");
20
21
        $this->stream = $fp;
22
    }
23
24
    public function info($message, array $context = array())
25
    {
26
        fwrite($this->stream, (string)$message . "\n");
27
    }
28
29
    public function warning($message, array $context = array())
30
    {
31
        $this->info('WARNING: ' . $message, $context);
32
    }
33
34
    public function debug($message, array $context = array())
35
    {
36
        $this->info('DEBUG: ' . $message, $context);
37
    }
38
39
    public function critical($message, array $context = array())
40
    {
41
        $this->info('CRITICAL: ' . $message, $context);
42
    }
43
44
    public function emergency($message, array $context = array())
45
    {
46
        $this->info('EMERGENCY: ' . $message, $context);
47
    }
48
49
    public function error($message, array $context = array())
50
    {
51
        $this->info('ERROR: ' . $message, $context);
52
    }
53
54
    public function alert($message, array $context = array())
55
    {
56
        $this->info('ALERT: ' . $message, $context);
57
    }
58
59
    public function notice($message, array $context = array())
60
    {
61
        $this->info('NOTICE: ' . $message, $context);
62
    }
63
64
    public function log($level, $message, array $context = array())
65
    {
66
        $this->info($message, $context);
67
    }
68
69
    /**
70
     *
71
     *
72
     * @return string
73
     */
74
    public function getLog()
75
    {
76
        rewind($this->stream);
77
78
        return stream_get_contents($this->stream);
79
    }
80
}
81
82
83
// Works
84
85
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
86
87
$filename = "php://memory";
88
89
$fp = fopen($filename, "w+b");
90
fwrite($fp, 'hi');
91
92
fwrite($fp, 'dude');
93
rewind($fp);
94
var_dump(stream_get_contents($fp));
95
fwrite($fp, 'dude');
96
rewind($fp);
97
var_dump(stream_get_contents($fp));
98
*/
99