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

JsonDataSource::getDataSourceReportParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 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\DataSource;
15
16
use Soluble\Jasper\DataSource\Contract\JRDataSourceFromReportParamsInterface;
17
use Soluble\Jasper\DataSource\Contract\JRDataSourceFromReportParamsTrait;
18
use Soluble\Jasper\DataSource\Contract\ReportParametrableInterface;
19
use Soluble\Jasper\ReportParams;
20
21
class JsonDataSource implements JRDataSourceFromReportParamsInterface, ReportParametrableInterface
22
{
23
    use JRDataSourceFromReportParamsTrait;
24
25
    public const PARAM_JSON_SOURCE = 'net.sf.jasperreports.json.source';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
26
    public const PARAM_JSON_DATE_PATTERN = 'net.sf.jasperreports.json.date.pattern';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
27
    public const PARAM_JSON_NUMBER_PATTERN = 'net.sf.jasperreports.json.number.pattern';
28
    public const PARAM_JSON_LOCALE_CODE = 'net.sf.jasperreports.json.locale.code';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
29
    public const PARAM_JSON_TIMEZONE_ID = 'net.sf.jasperreports.json.timezone.id';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
30
31
    public const DEFAULT_DATE_PATTERN = 'yyyy-MM-dd';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
32
    public const DEFAULT_NUMBER_PATTERN = '0.####';
33
    public const DEFAULT_LOCALE_CODE = 'en_US';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
34
    public const DEFAULT_TIMEZONE_ID = 'UTC';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
35
36
    /**
37
     * @var string
38
     */
39
    private $jsonSource;
40
41
    /**
42
     * @var array
43
     */
44
    private $options;
45
46
    /**
47
     * @param string $jsonSource  file or url for the json source
48
     * @param string $datePattern json date pattern in java style (i.e. 'yyyy-MM-dd')
49
     */
50 4
    public function __construct(
51
        string $jsonSource,
52
                                string $datePattern = self::DEFAULT_DATE_PATTERN,
53
                                string $numberPattern = self::DEFAULT_NUMBER_PATTERN,
54
                                string $timezoneId = self::PARAM_JSON_TIMEZONE_ID,
55
                                string $localeCode = self::PARAM_JSON_LOCALE_CODE
56
    ) {
57 4
        $this->jsonSource = $jsonSource;
58 4
        $this->setOptions([
59 4
                self::PARAM_JSON_SOURCE         => $jsonSource,
60 4
                self::PARAM_JSON_DATE_PATTERN   => $datePattern,
61 4
                self::PARAM_JSON_NUMBER_PATTERN => $numberPattern,
62 4
                self::PARAM_JSON_TIMEZONE_ID    => $timezoneId,
63 4
                self::PARAM_JSON_LOCALE_CODE    => $localeCode
64
        ]);
65 4
    }
66
67 4
    public function setOptions(array $options)
68
    {
69 4
        $options[self::PARAM_JSON_SOURCE] = $this->jsonSource;
70 4
        $this->options = $options;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 20 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
71 4
    }
72
73 1
    public function getOptions(): array
74
    {
75 1
        return $this->options;
76
    }
77
78 3
    public function getDataSourceReportParams(): ReportParams
79
    {
80 3
        return new ReportParams($this->options);
81
    }
82
}
83