Completed
Push — master ( 6a7da5...1827cf )
by Alec
08:13 queued 02:32
created

Reportable::resetReportObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\ReportInterface;
8
use AlecRabbit\Tools\Reports\Factory;
9
10
trait Reportable
11
{
12
    /** @var ReportInterface|null */
13
    protected $reportObject;
14
15
    /**
16
     * @param bool $rebuild Rebuild report object
17
     * @return ReportInterface
18
     */
19 12
    public function getReport(bool $rebuild = true): ReportInterface
20
    {
21 12
        if (null === $this->reportObject || true === $rebuild) {
22 12
            $this->prepareForReport();
23 12
            $this->reportObject =
24 12
                Factory::makeReport(
25
                    /** @scrutinizer ignore-type */
26 12
                    $this
27
                );
28
        }
29
        return
30 12
            $this->reportObject;
31
    }
32
33
    /**
34
     * Makes all necessary actions before report
35
     */
36 7
    protected function prepareForReport(): void
37
    {
38 7
    }
39
}
40