Test Setup Failed
Push — develop ( 7cd2b2...750858 )
by Alec
03:42
created

HasReport::report()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
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
    public function report(bool $rebuild = true): ReportInterface
21
    {
22
        if (true === $rebuild) {
23
            $this->meetConditions();
24
            $this->beforeReport();
25
            /** @var ReportableInterface $that */
26
            $that = $this;
27
            $this->report->buildOn($that); // $that used for static analysis
28
        }
29
        return
30
            $this->report;
31
    }
32
33
    /**
34
     * Makes all necessary actions before report
35
     */
36
    protected function beforeReport(): void
37
    {
38
    }
39
40
    /**
41
     * Checks if all conditions needed for report are met
42
     */
43
    protected function meetConditions(): void
44
    {
45
    }
46
}
47