Completed
Push — master ( c11c60...f0cca7 )
by Alec
03:39 queued 18s
created

Reportable   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 7
eloc 13
dl 0
loc 48
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A checkReport() 0 7 2
A beforeReport() 0 2 1
A report() 0 11 3
A checkConditions() 0 2 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Traits\ForReports\Core;
4
5
use AlecRabbit\Traits\ForReports\Contracts\ReportableInterface;
6
use AlecRabbit\Traits\ForReports\Contracts\ReportInterface;
7
8
abstract class Reportable implements ReportableInterface
9
{
10
    /** @var ReportInterface */
11
    protected $report;
12
13
    /**
14
     * @param bool $rebuild Rebuild report object
15
     * @return ReportInterface
16
     */
17 1
    public function report(bool $rebuild = true): ReportInterface
18
    {
19 1
        $rebuild = $this->checkReport() || $rebuild;
20 1
        if (true === $rebuild) {
21 1
            $this->checkConditions();
22 1
            $this->beforeReport();
23
            /** @noinspection PhpParamsInspection */
24 1
            $this->report->buildOn($this);
25
        }
26
        return
27 1
            $this->report;
28
    }
29
30
    /**
31
     * Checks if all conditions needed for report are met
32
     */
33 1
    protected function checkConditions(): void
34
    {
35 1
    }
36
37
    /**
38
     * Makes all necessary actions before report
39
     */
40 1
    protected function beforeReport(): void
41
    {
42 1
    }
43
44
    abstract protected function createEmptyReport(): ReportInterface;
45
46
    /**
47
     * @return bool
48
     */
49 1
    protected function checkReport(): bool
50
    {
51 1
        if (null === $this->report) {
52 1
            $this->report = $this->createEmptyReport();
53 1
            return true;
54
        }
55
        return false;
56
    }
57
}
58