Skip to content

More Scrutinizer Catch Up #3050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2590,21 +2590,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Worksheet/PageSetup.php

-
message: "#^Parameter \\#1 \\$value of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\PageSetup\\:\\:setFirstPageNumber\\(\\) expects int, null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/PageSetup.php

-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\PageSetup\\:\\:\\$pageOrder has no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/PageSetup.php

-
message: "#^Strict comparison using \\=\\=\\= between int\\<min, \\-1\\> and null will always evaluate to false\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/PageSetup.php

-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\SheetView\\:\\:\\$sheetViewTypes has no type specified\\.$#"
count: 1
Expand Down
22 changes: 11 additions & 11 deletions samples/Chart/33_Chart_create_line_dateaxis.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@
// marker details
$dataSeriesValues[0]
->getMarkerFillColor()
->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
$dataSeriesValues[0]
->getMarkerBorderColor()
->setColorProperties('002060', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
->setColorProperties('002060', null, ChartColor::EXCEL_COLOR_TYPE_RGB);

// line details - dashed, smooth line (Bezier) with arrows, 40% transparent
$dataSeriesValues[0]
Expand All @@ -129,18 +129,18 @@
->setColorProperties('accent6', 3, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
$dataSeriesValues[1] // square marker fill color
->getMarkerFillColor()
->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
$dataSeriesValues[1]
->setScatterLines(true)
->setSmoothLine(false)
->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_ARGB);
->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_RGB);
$dataSeriesValues[1]->setLineWidth(2.0);

// series 3 - metric3, markers, no line
$dataSeriesValues[2] // triangle? fill
//->setPointMarker('triangle') // let Excel choose shape, which is predicted to be a triangle
->getMarkerFillColor()
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
$dataSeriesValues[2] // triangle border
->getMarkerBorderColor()
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
Expand Down Expand Up @@ -239,7 +239,7 @@
->setScatterlines(false); // disable connecting lines
$dataSeriesValues[0]
->getMarkerFillColor()
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
$dataSeriesValues[0]
->getMarkerBorderColor()
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
Expand Down Expand Up @@ -326,7 +326,7 @@
// Set the position of the chart in the chart sheet below the first chart
$chart->setTopLeftPosition('A13');
$chart->setBottomRightPosition('P25');
$chart->setRoundedCorners('true'); // Rounded corners in Chart Outline
$chart->setRoundedCorners(true); // Rounded corners in Chart Outline

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

// get date of first day of the quarter of the start date
$startMonth = $startDate->format('n'); // suppress leading zero
$startYr = $startDate->format('Y');
$startMonth = (int) $startDate->format('n'); // suppress leading zero
$startYr = (int) $startDate->format('Y');
$qtr = intdiv($startMonth, 3) + (($startMonth % 3 > 0) ? 1 : 0);
$qtrStartMonth = sprintf('%02d', 1 + (($qtr - 1) * 3));
$qtrStartStr = "$startYr-$qtrStartMonth-01";
Expand All @@ -360,8 +360,8 @@ function dateRange(int $nrows, Spreadsheet $wrkbk): array
// end the xaxis at the end of the quarter of the last date
$lastDateStr = $dataSheet->getCellByColumnAndRow(2, $nrows + 1)->getValue();
$lastDate = DateTime::createFromFormat('Y-m-d', $lastDateStr);
$lastMonth = $lastDate->format('n');
$lastYr = $lastDate->format('Y');
$lastMonth = (int) $lastDate->format('n');
$lastYr = (int) $lastDate->format('Y');
$qtr = intdiv($lastMonth, 3) + (($lastMonth % 3 > 0) ? 1 : 0);
$qtrEndMonth = 3 + (($qtr - 1) * 3);
$lastDOM = cal_days_in_month(CAL_GREGORIAN, $qtrEndMonth, $lastYr);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Chart/Axis.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function setAxisType(string $type): self
* @param ?int $alpha
* @param ?string $AlphaType
*/
public function setFillParameters($color, $alpha = null, $AlphaType = self::EXCEL_COLOR_TYPE_ARGB): void
public function setFillParameters($color, $alpha = null, $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
{
$this->fillColor->setColorProperties($color, $alpha, $AlphaType);
}
Expand Down
6 changes: 4 additions & 2 deletions src/PhpSpreadsheet/Chart/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,11 @@ public function getRoundedCorners(): bool
return $this->roundedCorners;
}

public function setRoundedCorners(bool $roundedCorners): self
public function setRoundedCorners(?bool $roundedCorners): self
{
$this->roundedCorners = $roundedCorners;
if ($roundedCorners !== null) {
$this->roundedCorners = $roundedCorners;
}

return $this;
}
Expand Down
13 changes: 8 additions & 5 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,22 +306,25 @@ private static function castToBoolean(SimpleXMLElement $c): bool
return (bool) $c->v;
}

private static function castToError(SimpleXMLElement $c): ?string
private static function castToError(?SimpleXMLElement $c): ?string
{
return isset($c->v) ? (string) $c->v : null;
return isset($c, $c->v) ? (string) $c->v : null;
}

private static function castToString(SimpleXMLElement $c): ?string
private static function castToString(?SimpleXMLElement $c): ?string
{
return isset($c->v) ? (string) $c->v : null;
return isset($c, $c->v) ? (string) $c->v : null;
}

/**
* @param mixed $value
* @param mixed $calculatedValue
*/
private function castToFormula(SimpleXMLElement $c, string $r, string &$cellDataType, &$value, &$calculatedValue, array &$sharedFormulas, string $castBaseType): void
private function castToFormula(?SimpleXMLElement $c, string $r, string &$cellDataType, &$value, &$calculatedValue, array &$sharedFormulas, string $castBaseType): void
{
if ($c === null) {
return;
}
$attr = $c->f->attributes();
$cellDataType = 'f';
$value = "={$c->f}";
Expand Down
12 changes: 6 additions & 6 deletions src/PhpSpreadsheet/Reader/Xlsx/AutoFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ private function readDateRangeAutoFilter(SimpleXMLElement $filters, Column $colu
}
}

private function readCustomAutoFilter(SimpleXMLElement $filterColumn, Column $column): void
private function readCustomAutoFilter(?SimpleXMLElement $filterColumn, Column $column): void
{
if ($filterColumn->customFilters) {
if (isset($filterColumn, $filterColumn->customFilters)) {
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER);
$customFilters = $filterColumn->customFilters;
// Custom filters can an AND or an OR join;
Expand All @@ -104,9 +104,9 @@ private function readCustomAutoFilter(SimpleXMLElement $filterColumn, Column $co
}
}

private function readDynamicAutoFilter(SimpleXMLElement $filterColumn, Column $column): void
private function readDynamicAutoFilter(?SimpleXMLElement $filterColumn, Column $column): void
{
if ($filterColumn->dynamicFilter) {
if (isset($filterColumn, $filterColumn->dynamicFilter)) {
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER);
// We should only ever have one dynamic filter
foreach ($filterColumn->dynamicFilter as $filterRule) {
Expand All @@ -126,9 +126,9 @@ private function readDynamicAutoFilter(SimpleXMLElement $filterColumn, Column $c
}
}

private function readTopTenAutoFilter(SimpleXMLElement $filterColumn, Column $column): void
private function readTopTenAutoFilter(?SimpleXMLElement $filterColumn, Column $column): void
{
if ($filterColumn->top10) {
if (isset($filterColumn, $filterColumn->top10)) {
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_TOPTENFILTER);
// We should only ever have one top10 filter
foreach ($filterColumn->top10 as $filterRule) {
Expand Down
40 changes: 20 additions & 20 deletions src/PhpSpreadsheet/Reader/Xlsx/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use PhpOffice\PhpSpreadsheet\Chart\Layout;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Properties;
use PhpOffice\PhpSpreadsheet\Chart\Properties as ChartProperties;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\Chart\TrendLine;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
Expand Down Expand Up @@ -113,6 +113,7 @@ public function readChart(SimpleXMLElement $chartElements, $chartName)
$plotSeries = $plotAttributes = [];
$catAxRead = false;
$plotNoFill = false;
/** @var SimpleXMLElement $chartDetail */
foreach ($chartDetails as $chartDetailKey => $chartDetail) {
switch ($chartDetailKey) {
case 'spPr':
Expand All @@ -121,17 +122,18 @@ public function readChart(SimpleXMLElement $chartElements, $chartName)
$plotNoFill = true;
}
if (isset($possibleNoFill->gradFill->gsLst)) {
/** @var SimpleXMLElement $gradient */
foreach ($possibleNoFill->gradFill->gsLst->gs as $gradient) {
/** @var float */
$pos = self::getAttribute($gradient, 'pos', 'float');
$gradientArray[] = [
$pos / Properties::PERCENTAGE_MULTIPLIER,
$pos / ChartProperties::PERCENTAGE_MULTIPLIER,
new ChartColor($this->readColor($gradient)),
];
}
}
if (isset($possibleNoFill->gradFill->lin)) {
$gradientLin = Properties::XmlToAngle((string) self::getAttribute($possibleNoFill->gradFill->lin, 'ang', 'string'));
$gradientLin = ChartProperties::XmlToAngle((string) self::getAttribute($possibleNoFill->gradFill->lin, 'ang', 'string'));
}

break;
Expand Down Expand Up @@ -464,12 +466,13 @@ private function chartDataSeries(SimpleXMLElement $chartDetail, string $plotType
$pointSize = null;
$noFill = false;
$bubble3D = false;
$dPtColors = [];
$dptColors = [];
$markerFillColor = null;
$markerBorderColor = null;
$lineStyle = null;
$labelLayout = null;
$trendLines = [];
/** @var SimpleXMLElement $seriesDetail */
foreach ($seriesDetails as $seriesKey => $seriesDetail) {
switch ($seriesKey) {
case 'idx':
Expand All @@ -487,7 +490,6 @@ private function chartDataSeries(SimpleXMLElement $chartDetail, string $plotType
break;
case 'spPr':
$children = $seriesDetail->children($this->aNamespace);
$ln = $children->ln;
if (isset($children->ln)) {
$ln = $children->ln;
if (is_countable($ln->noFill) && count($ln->noFill) === 1) {
Expand Down Expand Up @@ -1161,15 +1163,15 @@ private function setChartAttributes(Layout $plotArea, $plotAttributes): void
}
}

private function readEffects(SimpleXMLElement $chartDetail, ?Properties $chartObject): void
private function readEffects(SimpleXMLElement $chartDetail, ?ChartProperties $chartObject): void
{
if (!isset($chartObject, $chartDetail->spPr)) {
return;
}
$sppr = $chartDetail->spPr->children($this->aNamespace);

if (isset($sppr->effectLst->glow)) {
$axisGlowSize = (float) self::getAttribute($sppr->effectLst->glow, 'rad', 'integer') / Properties::POINTS_WIDTH_MULTIPLIER;
$axisGlowSize = (float) self::getAttribute($sppr->effectLst->glow, 'rad', 'integer') / ChartProperties::POINTS_WIDTH_MULTIPLIER;
if ($axisGlowSize != 0.0) {
$colorArray = $this->readColor($sppr->effectLst->glow);
$chartObject->setGlowProperties($axisGlowSize, $colorArray['value'], $colorArray['alpha'], $colorArray['type']);
Expand All @@ -1180,7 +1182,7 @@ private function readEffects(SimpleXMLElement $chartDetail, ?Properties $chartOb
/** @var string */
$softEdgeSize = self::getAttribute($sppr->effectLst->softEdge, 'rad', 'string');
if (is_numeric($softEdgeSize)) {
$chartObject->setSoftEdges((float) Properties::xmlToPoints($softEdgeSize));
$chartObject->setSoftEdges((float) ChartProperties::xmlToPoints($softEdgeSize));
}
}

Expand All @@ -1195,28 +1197,28 @@ private function readEffects(SimpleXMLElement $chartDetail, ?Properties $chartOb
if ($type !== '') {
/** @var string */
$blur = self::getAttribute($sppr->effectLst->$type, 'blurRad', 'string');
$blur = is_numeric($blur) ? Properties::xmlToPoints($blur) : null;
$blur = is_numeric($blur) ? ChartProperties::xmlToPoints($blur) : null;
/** @var string */
$dist = self::getAttribute($sppr->effectLst->$type, 'dist', 'string');
$dist = is_numeric($dist) ? Properties::xmlToPoints($dist) : null;
$dist = is_numeric($dist) ? ChartProperties::xmlToPoints($dist) : null;
/** @var string */
$direction = self::getAttribute($sppr->effectLst->$type, 'dir', 'string');
$direction = is_numeric($direction) ? Properties::xmlToAngle($direction) : null;
$direction = is_numeric($direction) ? ChartProperties::xmlToAngle($direction) : null;
$algn = self::getAttribute($sppr->effectLst->$type, 'algn', 'string');
$rot = self::getAttribute($sppr->effectLst->$type, 'rotWithShape', 'string');
$size = [];
foreach (['sx', 'sy'] as $sizeType) {
$sizeValue = self::getAttribute($sppr->effectLst->$type, $sizeType, 'string');
if (is_numeric($sizeValue)) {
$size[$sizeType] = Properties::xmlToTenthOfPercent((string) $sizeValue);
$size[$sizeType] = ChartProperties::xmlToTenthOfPercent((string) $sizeValue);
} else {
$size[$sizeType] = null;
}
}
foreach (['kx', 'ky'] as $sizeType) {
$sizeValue = self::getAttribute($sppr->effectLst->$type, $sizeType, 'string');
if (is_numeric($sizeValue)) {
$size[$sizeType] = Properties::xmlToAngle((string) $sizeValue);
$size[$sizeType] = ChartProperties::xmlToAngle((string) $sizeValue);
} else {
$size[$sizeType] = null;
}
Expand Down Expand Up @@ -1273,7 +1275,7 @@ private function readColor(SimpleXMLElement $colorXml): array
return $result;
}

private function readLineStyle(SimpleXMLElement $chartDetail, ?Properties $chartObject): void
private function readLineStyle(SimpleXMLElement $chartDetail, ?ChartProperties $chartObject): void
{
if (!isset($chartObject, $chartDetail->spPr)) {
return;
Expand All @@ -1287,7 +1289,7 @@ private function readLineStyle(SimpleXMLElement $chartDetail, ?Properties $chart
/** @var string */
$lineWidthTemp = self::getAttribute($sppr->ln, 'w', 'string');
if (is_numeric($lineWidthTemp)) {
$lineWidth = Properties::xmlToPoints($lineWidthTemp);
$lineWidth = ChartProperties::xmlToPoints($lineWidthTemp);
}
/** @var string */
$compoundType = self::getAttribute($sppr->ln, 'cmpd', 'string');
Expand All @@ -1296,15 +1298,13 @@ private function readLineStyle(SimpleXMLElement $chartDetail, ?Properties $chart
/** @var string */
$capType = self::getAttribute($sppr->ln, 'cap', 'string');
if (isset($sppr->ln->miter)) {
$joinType = Properties::LINE_STYLE_JOIN_MITER;
$joinType = ChartProperties::LINE_STYLE_JOIN_MITER;
} elseif (isset($sppr->ln->bevel)) {
$joinType = Properties::LINE_STYLE_JOIN_BEVEL;
$joinType = ChartProperties::LINE_STYLE_JOIN_BEVEL;
} else {
$joinType = '';
}
$headArrowType = '';
$headArrowSize = '';
$endArrowType = '';
$endArrowSize = '';
/** @var string */
$headArrowType = self::getAttribute($sppr->ln->headEnd, 'type', 'string');
Expand Down Expand Up @@ -1403,7 +1403,7 @@ private function setAxisProperties(SimpleXMLElement $chartDetail, ?Axis $whichAx
/** @var string */
$textRotation = self::getAttribute($children->bodyPr, 'rot', 'string');
if (is_numeric($textRotation)) {
$whichAxis->setAxisOption('textRotation', (string) Properties::xmlToAngle($textRotation));
$whichAxis->setAxisOption('textRotation', (string) ChartProperties::xmlToAngle($textRotation));
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/PhpSpreadsheet/Worksheet/PageSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,11 @@ class PageSetup
/**
* First page number.
*
* @var int
* @var ?int
*/
private $firstPageNumber;

/** @var string */
private $pageOrder = self::PAGEORDER_DOWN_THEN_OVER;

/**
Expand Down Expand Up @@ -375,7 +376,7 @@ public function setScale($scale, $update = true)
{
// Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
// but it is apparently still able to handle any scale >= 0, where 0 results in 100
if (($scale >= 0) || $scale === null) {
if ($scale === null || $scale >= 0) {
$this->scale = $scale;
if ($update) {
$this->fitToPage = false;
Expand Down Expand Up @@ -845,7 +846,7 @@ public function addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $in
/**
* Get first page number.
*
* @return int
* @return ?int
*/
public function getFirstPageNumber()
{
Expand All @@ -855,7 +856,7 @@ public function getFirstPageNumber()
/**
* Set first page number.
*
* @param int $value
* @param ?int $value
*
* @return $this
*/
Expand Down
Loading