CspReport   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 14 3
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