| 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\DiffBarChart\DiffBarChartOptions; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @author Christophe Meneses |
||
| 14 | */ |
||
| 15 | class DiffBarChart extends BarChart implements DiffChart |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var DiffBarChartOptions |
||
| 19 | */ |
||
| 20 | protected ChartOptionsInterface $options; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var BarChart|ColumnChart |
||
| 24 | */ |
||
| 25 | private $oldChart; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var BarChart|ColumnChart |
||
| 29 | */ |
||
| 30 | private $newChart; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param BarChart|ColumnChart|object $oldChart |
||
| 34 | * @param BarChart|ColumnChart|object $newChart |
||
| 35 | * |
||
| 36 | * @throws GoogleChartsException |
||
| 37 | */ |
||
| 38 | public function __construct($oldChart, $newChart) |
||
| 39 | { |
||
| 40 | if ((!$oldChart instanceof ColumnChart && !$oldChart instanceof BarChart) |
||
| 41 | || (!$newChart instanceof ColumnChart && !$newChart instanceof BarChart)) { |
||
| 42 | throw new GoogleChartsException('Instance of ColumnChart or BarChart is expected'); |
||
| 43 | } |
||
| 44 | |||
| 45 | parent::__construct(); |
||
| 46 | |||
| 47 | $this->options = new DiffBarChartOptions(); |
||
| 48 | |||
| 49 | $this->oldChart = $oldChart; |
||
| 50 | $this->newChart = $newChart; |
||
| 51 | } |
||
| 52 | |||
| 53 | public function getOptions(): DiffBarChartOptions |
||
| 54 | { |
||
| 55 | return $this->options; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param DiffBarChartOptions $options |
||
| 60 | */ |
||
| 61 | public function setOptions(ChartOptionsInterface $options): DiffBarChart |
||
| 62 | { |
||
| 63 | $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\...art\DiffBarChartOptions. 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...
|
|||
| 64 | |||
| 65 | return $this; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @return BarChart|ColumnChart |
||
| 70 | */ |
||
| 71 | public function getOldChart(): Chart |
||
| 72 | { |
||
| 73 | return $this->oldChart; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @return BarChart|ColumnChart |
||
| 78 | */ |
||
| 79 | public function getNewChart(): Chart |
||
| 80 | { |
||
| 81 | return $this->newChart; |
||
| 82 | } |
||
| 83 | } |
||
| 84 |