File::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * CSP
4
 *
5
 * @author     Kenji Suzuki <https://github.com/kenjis>
6
 * @license    MIT License
7
 * @copyright  2014 Kenji Suzuki
8
 * @link       https://github.com/kenjis/php-csp-nonce-source
9
 */
10
11
namespace Kenjis\Csp\Logger;
12
13
class File implements LoggerInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $logfile;
19
20
    /**
21
     * @param string $logfile
22
     */
23
    public function __construct($logfile)
24
    {
25
        $this->logfile = $logfile;
26
    }
27
28
    /**
29
     * @param \stdClass report object
30
     */
31
    public function log(\stdClass $report)
32
    {
33
        $data = json_encode(
34
            $report,
35
            JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
36
        );
37
38
        file_put_contents($this->logfile, $data . "\n", LOCK_EX | FILE_APPEND);
39
    }
40
}
41