Completed
Push — master ( 152dcd...9d2605 )
by Alec
05:33 queued 02:40
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 declare(strict_types=1);
2
3
namespace AlecRabbit\Tools\Reports\Traits;
4
5
use AlecRabbit\Tools\Reports\Contracts\ReportableInterface;
6
use AlecRabbit\Tools\Reports\Contracts\ReportInterface;
7
8
trait HasReport
9
{
10
    /** @var ReportInterface */
11
    protected $report;
12
13
    /**
14
     * @param bool $rebuild Rebuild report object
15
     * @return ReportInterface
16
     * @throws \Exception
17
     */
18 36
    public function report(bool $rebuild = true): ReportInterface
19
    {
20 36
        if (true === $rebuild) {
21 36
            $this->meetConditions();
22 36
            $this->beforeReport();
23
            /** @var ReportableInterface $that */
24 36
            $that = $this;
25 36
            $this->report->buildOn($that); // $that used for static analysis
26
        }
27
        return
28 36
            $this->report;
29
    }
30
31
    /**
32
     * Makes all necessary actions before report
33
     */
34 36
    protected function beforeReport(): void
35
    {
36 36
    }
37
38
    /**
39
     * Checks if all conditions needed for report are met
40
     */
41 22
    protected function meetConditions(): void
42
    {
43 22
    }
44
}
45