Completed
Push — develop ( b733eb...69cb61 )
by Alec
06:31
created

Reportable::getReport()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: alec
4
 * Date: 01.12.18
5
 * Time: 20:25
6
 */
7
8
namespace AlecRabbit\Tools\Reports\Traits;
9
10
use AlecRabbit\Tools\Reports\Contracts\ReportInterface;
11
use AlecRabbit\Tools\Reports\Factory;
12
13
trait Reportable
14
{
15
    /** @var ReportInterface|null */
16
    protected $reportObject;
17
18
    /**
19
     * @return ReportInterface
20
     */
21 11
    public function getReport(): ReportInterface
22
    {
23 11
        if (null === $this->reportObject) {
24 11
            $this->prepareForReport();
25
            /** @var \AlecRabbit\Tools\Reports\Contracts\ReportableInterface $that */
26 11
            $that = $this; // for static analyzers
27 11
            $this->reportObject = Factory::makeReport($that);
28
        }
29
        return
30 11
            $this->reportObject;
31
    }
32
33 5
    public function resetReportObject(): void
34
    {
35 5
        $this->reportObject = null;
36 5
    }
37
38
    /**
39
     * Makes all necessary actions before report
40
     */
41 9
    protected function prepareForReport(): void
42
    {
43 9
    }
44
}
45