FileHandler::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Moon\Logger\Handler;
6
7
use Moon\Logger\Formatter\FormatterInterface;
8
9
class FileHandler implements HandlerInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    private $filename;
15
    /**
16
     * @var FormatterInterface
17
     */
18
    private $formatter;
19
20
    public function __construct(FormatterInterface $formatter, string $filename)
21
    {
22
        $this->formatter = $formatter;
23
        $this->filename = $filename;
24
    }
25
26 2 View Code Duplication
    public function add(string $name, string $level, $message, array $context = []): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28 2
        // Format the message
29 2
        $data = $this->formatter->interpolate($name, $level, $message, $context);
30 2
31
        // Push it to file
32
        \file_put_contents($this->filename, $data.PHP_EOL, FILE_APPEND);
33
    }
34
}
35