1 | <?php |
||
2 | |||
3 | namespace CMEN\GoogleChartsBundle\GoogleCharts\Charts\Diff; |
||
4 | |||
5 | use CMEN\GoogleChartsBundle\Exception\GoogleChartsException; |
||
6 | use CMEN\GoogleChartsBundle\GoogleCharts\Chart; |
||
7 | use CMEN\GoogleChartsBundle\GoogleCharts\Charts\BarChart; |
||
8 | use CMEN\GoogleChartsBundle\GoogleCharts\Charts\ColumnChart; |
||
9 | use CMEN\GoogleChartsBundle\GoogleCharts\Options\ChartOptionsInterface; |
||
10 | use CMEN\GoogleChartsBundle\GoogleCharts\Options\Diff\DiffColumnChart\DiffColumnChartOptions; |
||
11 | |||
12 | class DiffColumnChart extends ColumnChart implements DiffChart |
||
13 | { |
||
14 | /** |
||
15 | * @var DiffColumnChartOptions |
||
16 | */ |
||
17 | protected ChartOptionsInterface $options; |
||
18 | |||
19 | /** |
||
20 | * @var BarChart|ColumnChart |
||
21 | */ |
||
22 | private $oldChart; |
||
23 | |||
24 | /** |
||
25 | * @var BarChart|ColumnChart |
||
26 | */ |
||
27 | private $newChart; |
||
28 | |||
29 | /** |
||
30 | * @param BarChart|ColumnChart|object $oldChart |
||
31 | * @param BarChart|ColumnChart|object $newChart |
||
32 | * |
||
33 | * @throws GoogleChartsException |
||
34 | */ |
||
35 | public function __construct($oldChart, $newChart) |
||
36 | { |
||
37 | if ((!$oldChart instanceof ColumnChart && !$oldChart instanceof BarChart) |
||
38 | || (!$newChart instanceof ColumnChart && !$newChart instanceof BarChart)) { |
||
39 | throw new GoogleChartsException('Instance of ColumnChart or BarChart is expected'); |
||
40 | } |
||
41 | |||
42 | parent::__construct(); |
||
43 | |||
44 | $this->options = new DiffColumnChartOptions(); |
||
45 | |||
46 | $this->oldChart = $oldChart; |
||
47 | $this->newChart = $newChart; |
||
48 | } |
||
49 | |||
50 | public function getOptions(): DiffColumnChartOptions |
||
51 | { |
||
52 | return $this->options; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param DiffColumnChartOptions $options |
||
57 | */ |
||
58 | public function setOptions(ChartOptionsInterface $options): DiffColumnChart |
||
59 | { |
||
60 | $this->options = $options; |
||
0 ignored issues
–
show
$options is of type CMEN\GoogleChartsBundle\...s\ChartOptionsInterface , but the property $options was declared to be of type CMEN\GoogleChartsBundle\...\DiffColumnChartOptions . Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly. Either this assignment is in error or an instanceof check should be added for that assignment. class Alien {}
class Dalek extends Alien {}
class Plot
{
/** @var Dalek */
public $villain;
}
$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
$plot->villain = $alien;
}
Loading history...
|
|||
61 | |||
62 | return $this; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return BarChart|ColumnChart |
||
67 | */ |
||
68 | public function getOldChart(): Chart |
||
69 | { |
||
70 | return $this->oldChart; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return BarChart|ColumnChart |
||
75 | */ |
||
76 | public function getNewChart(): Chart |
||
77 | { |
||
78 | return $this->newChart; |
||
79 | } |
||
80 | } |
||
81 |