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

Reportable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getReport() 0 12 3
A prepareForReport() 0 2 1
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