Completed
Push — master ( 152dcd...9d2605 )
by Alec
05:33 queued 02:40
created

HasReport::beforeReport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
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