FileHandler::log()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Tleckie\Log\Handler;
4
5
use Tleckie\Log\Level;
6
7
/**
8
 * Class FileHandler
9
 *
10
 * @package Tleckie\Log
11
 * @author  Teodoro Leckie Westberg <[email protected]>
12
 */
13
class FileHandler extends AbstractHandler
14
{
15
    /** @var resource */
16
    protected $file;
17
18
    /**
19
     * FileHandler constructor.
20
     *
21
     * @param string $minimumLevel
22
     * @param string $file
23
     */
24
    public function __construct(string $minimumLevel = Level::DEBUG, string $file = '/tmp/error.log')
25
    {
26
        parent::__construct($minimumLevel);
27
28
        $this->file = $file;
29
    }
30
31
    /**
32
     * @param mixed  $level
33
     * @param string $message
34
     * @param array  $context
35
     */
36
    public function log($level, $message, array $context = array()): void
37
    {
38
        if ($this->canNotify($level)) {
39
            @file_put_contents($this->file, $message, FILE_APPEND);
40
        }
41
    }
42
}
43