Completed
Push — master ( ba86a8...110e22 )
by Alec
04:16 queued 41s
created

HasReport   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 35
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A report() 0 11 2
A meetConditions() 0 2 1
A beforeReport() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Tools\Reports\Traits;
6
7
use AlecRabbit\Tools\Reports\Contracts\ReportableInterface;
8
use AlecRabbit\Tools\Reports\Contracts\ReportInterface;
9
10
trait HasReport
11
{
12
    /** @var ReportInterface */
13
    protected $report;
14
15
    /**
16
     * @param bool $rebuild Rebuild report object
17
     * @return ReportInterface
18
     * @throws \Exception
19
     */
20 28
    public function report(bool $rebuild = true): ReportInterface
21
    {
22 28
        if (true === $rebuild) {
23 28
            $this->meetConditions();
24 28
            $this->beforeReport();
25
            /** @var ReportableInterface $that */
26 28
            $that = $this;
27 28
            $this->report->buildOn($that); // $that used for static analysis
28
        }
29
        return
30 28
            $this->report;
31
    }
32
33
    /**
34
     * Makes all necessary actions before report
35
     */
36 22
    protected function beforeReport(): void
37
    {
38 22
    }
39
40
    /**
41
     * Checks if all conditions needed for report are met
42
     */
43 14
    protected function meetConditions(): void
44
    {
45 14
    }
46
}
47