Completed
Push — master ( 8ad0e5...05ab4d )
by Alec
04:24
created

Reportable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 31
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getReport() 0 10 2
A prepareForReport() 0 2 1
A resetReportObject() 0 3 1
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
     * @throws \JakubOnderka\PhpConsoleColor\InvalidStyleException
21
     */
22 11
    public function getReport(): ReportInterface
23
    {
24 11
        if (null === $this->reportObject) {
25 11
            $this->prepareForReport();
26
            /** @var \AlecRabbit\Tools\Reports\Contracts\ReportableInterface $that */
27 11
            $that = $this; // for static analyzers
28 11
            $this->reportObject = Factory::makeReport($that);
29
        }
30
        return
31 11
            $this->reportObject;
32
    }
33
34 5
    public function resetReportObject(): void
35
    {
36 5
        $this->reportObject = null;
37 5
    }
38
39
    /**
40
     * Makes all necessary actions before report
41
     */
42 9
    protected function prepareForReport(): void
43
    {
44 9
    }
45
}
46