Completed
Push — master ( b3758e...d24b37 )
by Sébastien
04:19
created

Report   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 75
c 0
b 0
f 0
ccs 28
cts 28
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getReportParams() 0 3 1
A getStatus() 0 3 1
A getDataSource() 0 3 1
A __construct() 0 20 4
A getReportFile() 0 3 1
A setReportParams() 0 3 1
A getReportPath() 0 3 1
A setDataSource() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Jasper report integration for PHP
7
 *
8
 * @link      https://github.com/belgattitude/soluble-jasper
9
 * @author    Vanvelthem Sébastien
10
 * @copyright Copyright (c) 2017 Vanvelthem Sébastien
11
 * @license   MIT
12
 */
13
14
namespace Soluble\Jasper;
15
16
use Soluble\Jasper\DataSource\Contract\DataSourceInterface;
17
use Soluble\Jasper\Exception\ReportFileNotFoundException;
18
use Soluble\Jasper\Report\ReportStatusInterface;
19
20
class Report implements ReportStatusInterface
21
{
22
    /**
23
     * @var string
24
     */
25
    private $reportFile;
26
27
    /**
28
     * @var ReportParams
29
     */
30
    private $reportParams;
31
32
    /**
33
     * @var DataSourceInterface
34
     */
35
    private $dataSource;
36
37 21
    public function __construct(string $reportJRXMLFile, ReportParams $reportParams = null, DataSourceInterface $dataSource = null)
38
    {
39 21
        if (!file_exists($reportJRXMLFile)) {
40 1
            throw new ReportFileNotFoundException(
41 1
                sprintf(
42 1
                    'The report file "%s" cannot be found.',
43 1
                    $reportJRXMLFile
44
                )
45
            );
46
        }
47
48 20
        if ($reportParams !== null) {
49 9
            $this->setReportParams($reportParams);
50
        }
51
52 20
        if ($dataSource !== null) {
53 4
            $this->setDataSource($dataSource);
54
        }
55
56 20
        $this->reportFile = $reportJRXMLFile;
57 20
    }
58
59 9
    public function setReportParams(ReportParams $reportParams): void
60
    {
61 9
        $this->reportParams = $reportParams;
62 9
    }
63
64 9
    public function getReportParams(): ?ReportParams
65
    {
66 9
        return $this->reportParams;
67
    }
68
69 4
    public function setDataSource(DataSourceInterface $dataSource): void
70
    {
71 4
        $this->dataSource = $dataSource;
72 4
    }
73
74 9
    public function getDataSource(): ?DataSourceInterface
75
    {
76 9
        return $this->dataSource;
77
    }
78
79
    /**
80
     * @return string current jrxml report file
81
     */
82 15
    public function getReportFile(): string
83
    {
84 15
        return $this->reportFile;
85
    }
86
87 11
    public function getReportPath(): string
88
    {
89 11
        return dirname($this->reportFile);
90
    }
91
92 1
    public function getStatus(): string
93
    {
94 1
        return ReportStatusInterface::STATUS_FRESH;
95
    }
96
}
97