CspReport::__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;
12
13
class CspReport
14
{
15
    /**
16
     * @var \Kenjis\Csp\Logger\LoggerInterface
17
     */
18
    private $logger;
19
20
    /**
21
     * @param \Kenjis\Csp\Logger\LoggerInterface $logger
22
     */
23
    public function __construct(Logger\LoggerInterface $logger)
24
    {
25
        $this->logger = $logger;
26
    }
27
28
    /**
29
     * @param string $post CSP violation report, JSON string
30
     */
31
    public function process($post)
32
    {
33
        $report = json_decode($post);
34
35
        if ($report) {
36
            $report->date = date("Y-m-d H:i:s");
37
38
            foreach (getallheaders() as $name => $value) {
39
                $report->headers[$name] = $value;
40
            }
41
42
            $this->logger->log($report);
43
        }
44
    }
45
}
46