Skip to content

Commit b5f70de

Browse files
authored
More Scrutinizer Catch Up (PHPOffice#3050)
* More Scrutinizer Catch Up Continue the work of PR PHPOffice#3043 by attending to the 12 remaining 'new' issues. * Php 8.1 Problem One new null-instead-of-string problem.
1 parent 7e38073 commit b5f70de

File tree

14 files changed

+78
-88
lines changed

14 files changed

+78
-88
lines changed

phpstan-baseline.neon

-15
Original file line numberDiff line numberDiff line change
@@ -2590,21 +2590,6 @@ parameters:
25902590
count: 1
25912591
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
25922592

2593-
-
2594-
message: "#^Parameter \\#1 \\$value of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\PageSetup\\:\\:setFirstPageNumber\\(\\) expects int, null given\\.$#"
2595-
count: 1
2596-
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
2597-
2598-
-
2599-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\PageSetup\\:\\:\\$pageOrder has no type specified\\.$#"
2600-
count: 1
2601-
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
2602-
2603-
-
2604-
message: "#^Strict comparison using \\=\\=\\= between int\\<min, \\-1\\> and null will always evaluate to false\\.$#"
2605-
count: 1
2606-
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
2607-
26082593
-
26092594
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\SheetView\\:\\:\\$sheetViewTypes has no type specified\\.$#"
26102595
count: 1

samples/Chart/33_Chart_create_line_dateaxis.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@
101101
// marker details
102102
$dataSeriesValues[0]
103103
->getMarkerFillColor()
104-
->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
104+
->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
105105
$dataSeriesValues[0]
106106
->getMarkerBorderColor()
107-
->setColorProperties('002060', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
107+
->setColorProperties('002060', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
108108

109109
// line details - dashed, smooth line (Bezier) with arrows, 40% transparent
110110
$dataSeriesValues[0]
@@ -129,18 +129,18 @@
129129
->setColorProperties('accent6', 3, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
130130
$dataSeriesValues[1] // square marker fill color
131131
->getMarkerFillColor()
132-
->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
132+
->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
133133
$dataSeriesValues[1]
134134
->setScatterLines(true)
135135
->setSmoothLine(false)
136-
->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_ARGB);
136+
->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_RGB);
137137
$dataSeriesValues[1]->setLineWidth(2.0);
138138

139139
// series 3 - metric3, markers, no line
140140
$dataSeriesValues[2] // triangle? fill
141141
//->setPointMarker('triangle') // let Excel choose shape, which is predicted to be a triangle
142142
->getMarkerFillColor()
143-
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
143+
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
144144
$dataSeriesValues[2] // triangle border
145145
->getMarkerBorderColor()
146146
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
@@ -239,7 +239,7 @@
239239
->setScatterlines(false); // disable connecting lines
240240
$dataSeriesValues[0]
241241
->getMarkerFillColor()
242-
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
242+
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
243243
$dataSeriesValues[0]
244244
->getMarkerBorderColor()
245245
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
@@ -326,7 +326,7 @@
326326
// Set the position of the chart in the chart sheet below the first chart
327327
$chart->setTopLeftPosition('A13');
328328
$chart->setBottomRightPosition('P25');
329-
$chart->setRoundedCorners('true'); // Rounded corners in Chart Outline
329+
$chart->setRoundedCorners(true); // Rounded corners in Chart Outline
330330

331331
// Add the chart to the worksheet $chartSheet
332332
$chartSheet->addChart($chart);
@@ -350,8 +350,8 @@ function dateRange(int $nrows, Spreadsheet $wrkbk): array
350350
$startDate = DateTime::createFromFormat('Y-m-d', $startDateStr); // php date obj
351351

352352
// get date of first day of the quarter of the start date
353-
$startMonth = $startDate->format('n'); // suppress leading zero
354-
$startYr = $startDate->format('Y');
353+
$startMonth = (int) $startDate->format('n'); // suppress leading zero
354+
$startYr = (int) $startDate->format('Y');
355355
$qtr = intdiv($startMonth, 3) + (($startMonth % 3 > 0) ? 1 : 0);
356356
$qtrStartMonth = sprintf('%02d', 1 + (($qtr - 1) * 3));
357357
$qtrStartStr = "$startYr-$qtrStartMonth-01";
@@ -360,8 +360,8 @@ function dateRange(int $nrows, Spreadsheet $wrkbk): array
360360
// end the xaxis at the end of the quarter of the last date
361361
$lastDateStr = $dataSheet->getCellByColumnAndRow(2, $nrows + 1)->getValue();
362362
$lastDate = DateTime::createFromFormat('Y-m-d', $lastDateStr);
363-
$lastMonth = $lastDate->format('n');
364-
$lastYr = $lastDate->format('Y');
363+
$lastMonth = (int) $lastDate->format('n');
364+
$lastYr = (int) $lastDate->format('Y');
365365
$qtr = intdiv($lastMonth, 3) + (($lastMonth % 3 > 0) ? 1 : 0);
366366
$qtrEndMonth = 3 + (($qtr - 1) * 3);
367367
$lastDOM = cal_days_in_month(CAL_GREGORIAN, $qtrEndMonth, $lastYr);

src/PhpSpreadsheet/Chart/Axis.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function setAxisType(string $type): self
219219
* @param ?int $alpha
220220
* @param ?string $AlphaType
221221
*/
222-
public function setFillParameters($color, $alpha = null, $AlphaType = self::EXCEL_COLOR_TYPE_ARGB): void
222+
public function setFillParameters($color, $alpha = null, $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
223223
{
224224
$this->fillColor->setColorProperties($color, $alpha, $AlphaType);
225225
}

src/PhpSpreadsheet/Chart/Chart.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,11 @@ public function getRoundedCorners(): bool
774774
return $this->roundedCorners;
775775
}
776776

777-
public function setRoundedCorners(bool $roundedCorners): self
777+
public function setRoundedCorners(?bool $roundedCorners): self
778778
{
779-
$this->roundedCorners = $roundedCorners;
779+
if ($roundedCorners !== null) {
780+
$this->roundedCorners = $roundedCorners;
781+
}
780782

781783
return $this;
782784
}

src/PhpSpreadsheet/Reader/Xlsx.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,25 @@ private static function castToBoolean(SimpleXMLElement $c): bool
306306
return (bool) $c->v;
307307
}
308308

309-
private static function castToError(SimpleXMLElement $c): ?string
309+
private static function castToError(?SimpleXMLElement $c): ?string
310310
{
311-
return isset($c->v) ? (string) $c->v : null;
311+
return isset($c, $c->v) ? (string) $c->v : null;
312312
}
313313

314-
private static function castToString(SimpleXMLElement $c): ?string
314+
private static function castToString(?SimpleXMLElement $c): ?string
315315
{
316-
return isset($c->v) ? (string) $c->v : null;
316+
return isset($c, $c->v) ? (string) $c->v : null;
317317
}
318318

319319
/**
320320
* @param mixed $value
321321
* @param mixed $calculatedValue
322322
*/
323-
private function castToFormula(SimpleXMLElement $c, string $r, string &$cellDataType, &$value, &$calculatedValue, array &$sharedFormulas, string $castBaseType): void
323+
private function castToFormula(?SimpleXMLElement $c, string $r, string &$cellDataType, &$value, &$calculatedValue, array &$sharedFormulas, string $castBaseType): void
324324
{
325+
if ($c === null) {
326+
return;
327+
}
325328
$attr = $c->f->attributes();
326329
$cellDataType = 'f';
327330
$value = "={$c->f}";

src/PhpSpreadsheet/Reader/Xlsx/AutoFilter.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ private function readDateRangeAutoFilter(SimpleXMLElement $filters, Column $colu
8585
}
8686
}
8787

88-
private function readCustomAutoFilter(SimpleXMLElement $filterColumn, Column $column): void
88+
private function readCustomAutoFilter(?SimpleXMLElement $filterColumn, Column $column): void
8989
{
90-
if ($filterColumn->customFilters) {
90+
if (isset($filterColumn, $filterColumn->customFilters)) {
9191
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER);
9292
$customFilters = $filterColumn->customFilters;
9393
// Custom filters can an AND or an OR join;
@@ -104,9 +104,9 @@ private function readCustomAutoFilter(SimpleXMLElement $filterColumn, Column $co
104104
}
105105
}
106106

107-
private function readDynamicAutoFilter(SimpleXMLElement $filterColumn, Column $column): void
107+
private function readDynamicAutoFilter(?SimpleXMLElement $filterColumn, Column $column): void
108108
{
109-
if ($filterColumn->dynamicFilter) {
109+
if (isset($filterColumn, $filterColumn->dynamicFilter)) {
110110
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER);
111111
// We should only ever have one dynamic filter
112112
foreach ($filterColumn->dynamicFilter as $filterRule) {
@@ -126,9 +126,9 @@ private function readDynamicAutoFilter(SimpleXMLElement $filterColumn, Column $c
126126
}
127127
}
128128

129-
private function readTopTenAutoFilter(SimpleXMLElement $filterColumn, Column $column): void
129+
private function readTopTenAutoFilter(?SimpleXMLElement $filterColumn, Column $column): void
130130
{
131-
if ($filterColumn->top10) {
131+
if (isset($filterColumn, $filterColumn->top10)) {
132132
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_TOPTENFILTER);
133133
// We should only ever have one top10 filter
134134
foreach ($filterColumn->top10 as $filterRule) {

src/PhpSpreadsheet/Reader/Xlsx/Chart.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use PhpOffice\PhpSpreadsheet\Chart\Layout;
1212
use PhpOffice\PhpSpreadsheet\Chart\Legend;
1313
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
14-
use PhpOffice\PhpSpreadsheet\Chart\Properties;
14+
use PhpOffice\PhpSpreadsheet\Chart\Properties as ChartProperties;
1515
use PhpOffice\PhpSpreadsheet\Chart\Title;
1616
use PhpOffice\PhpSpreadsheet\Chart\TrendLine;
1717
use PhpOffice\PhpSpreadsheet\RichText\RichText;
@@ -113,6 +113,7 @@ public function readChart(SimpleXMLElement $chartElements, $chartName)
113113
$plotSeries = $plotAttributes = [];
114114
$catAxRead = false;
115115
$plotNoFill = false;
116+
/** @var SimpleXMLElement $chartDetail */
116117
foreach ($chartDetails as $chartDetailKey => $chartDetail) {
117118
switch ($chartDetailKey) {
118119
case 'spPr':
@@ -121,17 +122,18 @@ public function readChart(SimpleXMLElement $chartElements, $chartName)
121122
$plotNoFill = true;
122123
}
123124
if (isset($possibleNoFill->gradFill->gsLst)) {
125+
/** @var SimpleXMLElement $gradient */
124126
foreach ($possibleNoFill->gradFill->gsLst->gs as $gradient) {
125127
/** @var float */
126128
$pos = self::getAttribute($gradient, 'pos', 'float');
127129
$gradientArray[] = [
128-
$pos / Properties::PERCENTAGE_MULTIPLIER,
130+
$pos / ChartProperties::PERCENTAGE_MULTIPLIER,
129131
new ChartColor($this->readColor($gradient)),
130132
];
131133
}
132134
}
133135
if (isset($possibleNoFill->gradFill->lin)) {
134-
$gradientLin = Properties::XmlToAngle((string) self::getAttribute($possibleNoFill->gradFill->lin, 'ang', 'string'));
136+
$gradientLin = ChartProperties::XmlToAngle((string) self::getAttribute($possibleNoFill->gradFill->lin, 'ang', 'string'));
135137
}
136138

137139
break;
@@ -464,12 +466,13 @@ private function chartDataSeries(SimpleXMLElement $chartDetail, string $plotType
464466
$pointSize = null;
465467
$noFill = false;
466468
$bubble3D = false;
467-
$dPtColors = [];
469+
$dptColors = [];
468470
$markerFillColor = null;
469471
$markerBorderColor = null;
470472
$lineStyle = null;
471473
$labelLayout = null;
472474
$trendLines = [];
475+
/** @var SimpleXMLElement $seriesDetail */
473476
foreach ($seriesDetails as $seriesKey => $seriesDetail) {
474477
switch ($seriesKey) {
475478
case 'idx':
@@ -487,7 +490,6 @@ private function chartDataSeries(SimpleXMLElement $chartDetail, string $plotType
487490
break;
488491
case 'spPr':
489492
$children = $seriesDetail->children($this->aNamespace);
490-
$ln = $children->ln;
491493
if (isset($children->ln)) {
492494
$ln = $children->ln;
493495
if (is_countable($ln->noFill) && count($ln->noFill) === 1) {
@@ -1161,15 +1163,15 @@ private function setChartAttributes(Layout $plotArea, $plotAttributes): void
11611163
}
11621164
}
11631165

1164-
private function readEffects(SimpleXMLElement $chartDetail, ?Properties $chartObject): void
1166+
private function readEffects(SimpleXMLElement $chartDetail, ?ChartProperties $chartObject): void
11651167
{
11661168
if (!isset($chartObject, $chartDetail->spPr)) {
11671169
return;
11681170
}
11691171
$sppr = $chartDetail->spPr->children($this->aNamespace);
11701172

11711173
if (isset($sppr->effectLst->glow)) {
1172-
$axisGlowSize = (float) self::getAttribute($sppr->effectLst->glow, 'rad', 'integer') / Properties::POINTS_WIDTH_MULTIPLIER;
1174+
$axisGlowSize = (float) self::getAttribute($sppr->effectLst->glow, 'rad', 'integer') / ChartProperties::POINTS_WIDTH_MULTIPLIER;
11731175
if ($axisGlowSize != 0.0) {
11741176
$colorArray = $this->readColor($sppr->effectLst->glow);
11751177
$chartObject->setGlowProperties($axisGlowSize, $colorArray['value'], $colorArray['alpha'], $colorArray['type']);
@@ -1180,7 +1182,7 @@ private function readEffects(SimpleXMLElement $chartDetail, ?Properties $chartOb
11801182
/** @var string */
11811183
$softEdgeSize = self::getAttribute($sppr->effectLst->softEdge, 'rad', 'string');
11821184
if (is_numeric($softEdgeSize)) {
1183-
$chartObject->setSoftEdges((float) Properties::xmlToPoints($softEdgeSize));
1185+
$chartObject->setSoftEdges((float) ChartProperties::xmlToPoints($softEdgeSize));
11841186
}
11851187
}
11861188

@@ -1195,28 +1197,28 @@ private function readEffects(SimpleXMLElement $chartDetail, ?Properties $chartOb
11951197
if ($type !== '') {
11961198
/** @var string */
11971199
$blur = self::getAttribute($sppr->effectLst->$type, 'blurRad', 'string');
1198-
$blur = is_numeric($blur) ? Properties::xmlToPoints($blur) : null;
1200+
$blur = is_numeric($blur) ? ChartProperties::xmlToPoints($blur) : null;
11991201
/** @var string */
12001202
$dist = self::getAttribute($sppr->effectLst->$type, 'dist', 'string');
1201-
$dist = is_numeric($dist) ? Properties::xmlToPoints($dist) : null;
1203+
$dist = is_numeric($dist) ? ChartProperties::xmlToPoints($dist) : null;
12021204
/** @var string */
12031205
$direction = self::getAttribute($sppr->effectLst->$type, 'dir', 'string');
1204-
$direction = is_numeric($direction) ? Properties::xmlToAngle($direction) : null;
1206+
$direction = is_numeric($direction) ? ChartProperties::xmlToAngle($direction) : null;
12051207
$algn = self::getAttribute($sppr->effectLst->$type, 'algn', 'string');
12061208
$rot = self::getAttribute($sppr->effectLst->$type, 'rotWithShape', 'string');
12071209
$size = [];
12081210
foreach (['sx', 'sy'] as $sizeType) {
12091211
$sizeValue = self::getAttribute($sppr->effectLst->$type, $sizeType, 'string');
12101212
if (is_numeric($sizeValue)) {
1211-
$size[$sizeType] = Properties::xmlToTenthOfPercent((string) $sizeValue);
1213+
$size[$sizeType] = ChartProperties::xmlToTenthOfPercent((string) $sizeValue);
12121214
} else {
12131215
$size[$sizeType] = null;
12141216
}
12151217
}
12161218
foreach (['kx', 'ky'] as $sizeType) {
12171219
$sizeValue = self::getAttribute($sppr->effectLst->$type, $sizeType, 'string');
12181220
if (is_numeric($sizeValue)) {
1219-
$size[$sizeType] = Properties::xmlToAngle((string) $sizeValue);
1221+
$size[$sizeType] = ChartProperties::xmlToAngle((string) $sizeValue);
12201222
} else {
12211223
$size[$sizeType] = null;
12221224
}
@@ -1273,7 +1275,7 @@ private function readColor(SimpleXMLElement $colorXml): array
12731275
return $result;
12741276
}
12751277

1276-
private function readLineStyle(SimpleXMLElement $chartDetail, ?Properties $chartObject): void
1278+
private function readLineStyle(SimpleXMLElement $chartDetail, ?ChartProperties $chartObject): void
12771279
{
12781280
if (!isset($chartObject, $chartDetail->spPr)) {
12791281
return;
@@ -1287,7 +1289,7 @@ private function readLineStyle(SimpleXMLElement $chartDetail, ?Properties $chart
12871289
/** @var string */
12881290
$lineWidthTemp = self::getAttribute($sppr->ln, 'w', 'string');
12891291
if (is_numeric($lineWidthTemp)) {
1290-
$lineWidth = Properties::xmlToPoints($lineWidthTemp);
1292+
$lineWidth = ChartProperties::xmlToPoints($lineWidthTemp);
12911293
}
12921294
/** @var string */
12931295
$compoundType = self::getAttribute($sppr->ln, 'cmpd', 'string');
@@ -1296,15 +1298,13 @@ private function readLineStyle(SimpleXMLElement $chartDetail, ?Properties $chart
12961298
/** @var string */
12971299
$capType = self::getAttribute($sppr->ln, 'cap', 'string');
12981300
if (isset($sppr->ln->miter)) {
1299-
$joinType = Properties::LINE_STYLE_JOIN_MITER;
1301+
$joinType = ChartProperties::LINE_STYLE_JOIN_MITER;
13001302
} elseif (isset($sppr->ln->bevel)) {
1301-
$joinType = Properties::LINE_STYLE_JOIN_BEVEL;
1303+
$joinType = ChartProperties::LINE_STYLE_JOIN_BEVEL;
13021304
} else {
13031305
$joinType = '';
13041306
}
1305-
$headArrowType = '';
13061307
$headArrowSize = '';
1307-
$endArrowType = '';
13081308
$endArrowSize = '';
13091309
/** @var string */
13101310
$headArrowType = self::getAttribute($sppr->ln->headEnd, 'type', 'string');
@@ -1403,7 +1403,7 @@ private function setAxisProperties(SimpleXMLElement $chartDetail, ?Axis $whichAx
14031403
/** @var string */
14041404
$textRotation = self::getAttribute($children->bodyPr, 'rot', 'string');
14051405
if (is_numeric($textRotation)) {
1406-
$whichAxis->setAxisOption('textRotation', (string) Properties::xmlToAngle($textRotation));
1406+
$whichAxis->setAxisOption('textRotation', (string) ChartProperties::xmlToAngle($textRotation));
14071407
}
14081408
}
14091409
}

src/PhpSpreadsheet/Worksheet/PageSetup.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,11 @@ class PageSetup
259259
/**
260260
* First page number.
261261
*
262-
* @var int
262+
* @var ?int
263263
*/
264264
private $firstPageNumber;
265265

266+
/** @var string */
266267
private $pageOrder = self::PAGEORDER_DOWN_THEN_OVER;
267268

268269
/**
@@ -375,7 +376,7 @@ public function setScale($scale, $update = true)
375376
{
376377
// Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
377378
// but it is apparently still able to handle any scale >= 0, where 0 results in 100
378-
if (($scale >= 0) || $scale === null) {
379+
if ($scale === null || $scale >= 0) {
379380
$this->scale = $scale;
380381
if ($update) {
381382
$this->fitToPage = false;
@@ -845,7 +846,7 @@ public function addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $in
845846
/**
846847
* Get first page number.
847848
*
848-
* @return int
849+
* @return ?int
849850
*/
850851
public function getFirstPageNumber()
851852
{
@@ -855,7 +856,7 @@ public function getFirstPageNumber()
855856
/**
856857
* Set first page number.
857858
*
858-
* @param int $value
859+
* @param ?int $value
859860
*
860861
* @return $this
861862
*/

0 commit comments

Comments
 (0)