Report   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 1
cbo 2
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getTotalImpact() 0 6 1
A __toString() 0 7 1
1
<?php
2
3
namespace Ionut\Sylar;
4
5
6
use Ionut\Sylar\Filters\FilterReportInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
9
/**
10
 * Sums all the FilterReports for the current request.
11
 */
12
class Report
13
{
14
15
    /**
16
     * @var FilterReportInterface[]
17
     */
18
    protected $filterReports;
19
20
    /**
21
     * @var ServerRequestInterface
22
     */
23
    protected $request;
24
25
    /**
26
     * @param  FilterReportInterface[]  $filterReports
27
     * @param  ServerRequestInterface   $request
28
     */
29
    public function __construct(array $filterReports, ServerRequestInterface $request)
30
    {
31
        $this->filterReports = $filterReports;
32
        $this->request = $request;
33
    }
34
35
    /**
36
     * Calculate the total impact of the contained filter reports.
37
     *
38
     * @return int
39
     */
40
    public function getTotalImpact()
41
    {
42
        return array_reduce($this->filterReports, function($carry, FilterReportInterface $filterReport) {
43
            return $carry + $filterReport->getImpact();
44
        });
45
    }
46
47
    /**
48
     * Export the report to a human-readable string.
49
     *
50
     * @return string
51
     */
52
    public function __toString()
53
    {
54
        $datetime = (new \DateTime())->format(\DateTime::ISO8601);
55
56
        $filterReports = implode("\n\n", $this->filterReports);
57
        return "[$datetime] {$this->request->getUri()}\n\n{$filterReports}";
58
    }
59
}