Skip to content

Catch Up With Some Scrutinizer Messages #3043

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 2 commits into from
Sep 4, 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
6 changes: 3 additions & 3 deletions samples/Chart/33_Chart_create_scatter2.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use PhpOffice\PhpSpreadsheet\Chart\Axis;
use PhpOffice\PhpSpreadsheet\Chart\Axis as ChartAxis;
use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
Expand Down Expand Up @@ -121,12 +121,12 @@
$dataSeriesValues[2]->setScatterLines(false); // points not connected

// Added so that Xaxis shows dates instead of Excel-equivalent-year1900-numbers
$xAxis = new Axis();
$xAxis = new ChartAxis();
//$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE );
$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true);
$xAxis->setAxisOption('textRotation', '45');

$yAxis = new Axis();
$yAxis = new ChartAxis();
$yAxis->setLineStyleProperties(
2.5, // width in points
Properties::LINE_STYLE_COMPOUND_SIMPLE,
Expand Down
6 changes: 3 additions & 3 deletions samples/Chart/33_Chart_create_scatter3.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use PhpOffice\PhpSpreadsheet\Chart\Axis;
use PhpOffice\PhpSpreadsheet\Chart\Axis as ChartAxis;
use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
Expand Down Expand Up @@ -121,13 +121,13 @@
$dataSeriesValues[2]->setScatterLines(false); // points not connected

// Added so that Xaxis shows dates instead of Excel-equivalent-year1900-numbers
$xAxis = new Axis();
$xAxis = new ChartAxis();
//$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE );
$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true);
$xAxis->setAxisOption('textRotation', '45');
$xAxis->setAxisOption('hidden', '1');

$yAxis = new Axis();
$yAxis = new ChartAxis();
$yAxis->setLineStyleProperties(
2.5, // width in points
Properties::LINE_STYLE_COMPOUND_SIMPLE,
Expand Down
18 changes: 9 additions & 9 deletions samples/Chart/33_Chart_create_scatter5_trendlines.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use PhpOffice\PhpSpreadsheet\Chart\Axis;
use PhpOffice\PhpSpreadsheet\Chart\Axis as ChartAxis;
use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
Expand Down Expand Up @@ -77,10 +77,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 @@ -105,24 +105,24 @@
->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);
$dataSeriesValues[2]->setScatterLines(false); // points not connected
// Added so that Xaxis shows dates instead of Excel-equivalent-year1900-numbers
$xAxis = new Axis();
$xAxis = new ChartAxis();
$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true);

// Build the dataseries
Expand Down Expand Up @@ -204,7 +204,7 @@

$dataSeriesValues[0]->setScatterLines(false); // points not connected
$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 All @@ -218,7 +218,7 @@
$dataSeriesValues[0]->getTrendLines()[2]->getLineColor()->setColorProperties('accent2', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
$dataSeriesValues[0]->getTrendLines()[2]->setLineStyleProperties(1.5, null, null, null, null, null, null, Properties::LINE_STYLE_ARROW_TYPE_OPEN, 8);

$xAxis = new Axis();
$xAxis = new ChartAxis();
$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601); // m/d/yyyy

// Build the dataseries
Expand Down
10 changes: 5 additions & 5 deletions src/PhpSpreadsheet/Chart/DataSeriesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ public function getFillColor()
if (is_array($this->fillColor)) {
$array = [];
foreach ($this->fillColor as $chartColor) {
$array[] = self::chartColorToString($chartColor);
$array[] = $this->chartColorToString($chartColor);
}

return $array;
}

return self::chartColorToString($this->fillColor);
return $this->chartColorToString($this->fillColor);
}

/**
Expand All @@ -348,13 +348,13 @@ public function setFillColor($color)
if ($fillString instanceof ChartColor) {
$this->fillColor[] = $fillString;
} else {
$this->fillColor[] = self::stringToChartColor($fillString);
$this->fillColor[] = $this->stringToChartColor($fillString);
}
}
} elseif ($color instanceof ChartColor) {
$this->fillColor = $color;
} elseif (is_string($color)) {
$this->fillColor = self::stringToChartColor($color);
} else {
$this->fillColor = $this->stringToChartColor($color);
}

return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Reader/Xlsx/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public function readChart(SimpleXMLElement $chartElements, $chartName)
break;
case 'stockChart':
$plotSeries[] = $this->chartDataSeries($chartDetail, $chartDetailKey);
$plotAttributes = $this->readChartAttributes($plotAreaLayout);
$plotAttributes = $this->readChartAttributes($chartDetail);

break;
}
Expand Down Expand Up @@ -1068,7 +1068,7 @@ private function parseRichText(SimpleXMLElement $titleDetailPart): RichText
}

/**
* @param null|Layout|SimpleXMLElement $chartDetail
* @param ?SimpleXMLElement $chartDetail
*/
private function readChartAttributes($chartDetail): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Shared/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public static function calculateColumnWidth(

// Special case if there are one or more newline characters ("\n")
$cellText = $cellText ?? '';
if (strpos($cellText, "\n") !== false) {
if (strpos(/** @scrutinizer ignore-type */ $cellText, "\n") !== false) {
$lineTexts = explode("\n", $cellText);
$lineWidths = [];
foreach ($lineTexts as $lineText) {
Expand Down
16 changes: 13 additions & 3 deletions src/PhpSpreadsheet/Shared/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,19 @@ public static function sanitizeUTF8(string $textValue): string
mb_substitute_character(65533); // Unicode substitution character
// Phpstan does not think this can return false.
$returnValue = mb_convert_encoding($textValue, 'UTF-8', 'UTF-8');
mb_substitute_character($subst);
mb_substitute_character(/** @scrutinizer ignore-type */ $subst);

return $returnValue;
return self::returnString($returnValue);
}

/**
* Strictly to satisfy Scrutinizer.
*
* @param mixed $value
*/
private static function returnString($value): string
{
return is_string($value) ? $value : '';
}

/**
Expand Down Expand Up @@ -433,7 +443,7 @@ public static function convertEncoding(string $textValue, string $to, string $fr
}
}

return mb_convert_encoding($textValue, $to, $from);
return self::returnString(mb_convert_encoding($textValue, $to, $from));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/PhpSpreadsheet/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -743,14 +743,14 @@ public function setColor(Color $color)

private function hashChartColor(?ChartColor $underlineColor): string
{
if ($this->underlineColor === null) {
if ($underlineColor === null) {
return '';
}

return
$this->underlineColor->getValue()
. $this->underlineColor->getType()
. (string) $this->underlineColor->getAlpha();
$underlineColor->getValue()
. $underlineColor->getType()
. (string) $underlineColor->getAlpha();
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/PhpSpreadsheet/Writer/Pdf/Dompdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public function save($filename, int $flags = 0): void
{
$fileHandle = parent::prepareForSave($filename);

// Default PDF paper size
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)

// Check for paper size and page orientation
$setup = $this->spreadsheet->getSheet($this->getSheetIndex() ?? 0)->getPageSetup();
$orientation = $this->getOrientation() ?? $setup->getOrientation();
Expand Down
3 changes: 0 additions & 3 deletions src/PhpSpreadsheet/Writer/Xlsx/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ private function writePlotArea(XMLWriter $objWriter, ?PlotArea $plotArea, ?Title
if ($plotArea === null) {
return;
}
$majorGridlines = ($yAxis === null) ? null : $yAxis->getMajorGridlines();
$minorGridlines = ($yAxis === null) ? null : $yAxis->getMinorGridlines();

$id1 = $id2 = $id3 = '0';
$this->seriesIndex = 0;
Expand Down Expand Up @@ -1163,7 +1161,6 @@ private function writePlotGroup(?DataSeries $plotGroup, string $groupType, XMLWr
$intercept = $trendLine->getIntercept();
$name = $trendLine->getName();
$trendLineColor = $trendLine->getLineColor(); // ChartColor
$trendLineWidth = $trendLine->getLineStyleProperty('width');

$objWriter->startElement('c:trendline'); // N.B. lowercase 'ell'
if ($name !== '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function testNullFormula(): void
{
$this->expectException(CalcException::class);
$this->expectExceptionMessage('Invalid parameter passed: formula');
$result = new FormulaParser(null);
new FormulaParser(null);
}

public function testInvalidTokenId(): void
Expand Down
6 changes: 3 additions & 3 deletions tests/PhpSpreadsheetTests/Chart/AxisGlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Chart;

use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Properties;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
Expand Down Expand Up @@ -107,7 +107,7 @@ public function testGlowY(): void
$yAxis = $chart->getChartAxisY();
$xAxis = $chart->getChartAxisX();
$yGlowSize = 10.0;
$yAxis->setGlowProperties($yGlowSize, 'FFFF00', 30, Properties::EXCEL_COLOR_TYPE_ARGB);
$yAxis->setGlowProperties($yGlowSize, 'FFFF00', 30, ChartColor::EXCEL_COLOR_TYPE_RGB);
$expectedGlowColor = [
'type' => 'srgbClr',
'value' => 'FFFF00',
Expand Down Expand Up @@ -231,7 +231,7 @@ public function testGlowX(): void
);
$yAxis = $chart->getChartAxisX(); // deliberate
$yGlowSize = 20.0;
$yAxis->setGlowProperties($yGlowSize, 'accent1', 20, Properties::EXCEL_COLOR_TYPE_SCHEME);
$yAxis->setGlowProperties($yGlowSize, 'accent1', 20, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
$expectedGlowColor = [
'type' => 'schemeClr',
'value' => 'accent1',
Expand Down
6 changes: 3 additions & 3 deletions tests/PhpSpreadsheetTests/Chart/AxisShadowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Chart;

use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Properties;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
Expand Down Expand Up @@ -113,7 +113,7 @@ public function testGlowY(): void
'distance' => 3,
'rotWithShape' => 0,
'color' => [
'type' => Properties::EXCEL_COLOR_TYPE_STANDARD,
'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
'value' => 'black',
'alpha' => 40,
],
Expand All @@ -139,7 +139,7 @@ public function testGlowY(): void
'ky' => null,
],
'color' => [
'type' => Properties::EXCEL_COLOR_TYPE_ARGB,
'type' => ChartColor::EXCEL_COLOR_TYPE_RGB,
'value' => 'FF0000',
'alpha' => 20,
],
Expand Down
6 changes: 3 additions & 3 deletions tests/PhpSpreadsheetTests/Chart/GridlinesShadowGlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use PhpOffice\PhpSpreadsheet\Chart\Axis;
use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\GridLines;
use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Properties;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
Expand Down Expand Up @@ -98,7 +98,7 @@ public function testGlowY(): void
$majorGridlines = new GridLines();
$yAxis->setMajorGridlines($majorGridlines);
$majorGlowSize = 10.0;
$majorGridlines->setGlowProperties($majorGlowSize, 'FFFF00', 30, Properties::EXCEL_COLOR_TYPE_ARGB);
$majorGridlines->setGlowProperties($majorGlowSize, 'FFFF00', 30, ChartColor::EXCEL_COLOR_TYPE_RGB);
$softEdgeSize = 2.5;
$majorGridlines->setSoftEdges($softEdgeSize);
$expectedGlowColor = [
Expand All @@ -122,7 +122,7 @@ public function testGlowY(): void
'distance' => 3,
'rotWithShape' => 0,
'color' => [
'type' => Properties::EXCEL_COLOR_TYPE_STANDARD,
'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
'value' => 'black',
'alpha' => 40,
],
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpSpreadsheetTests/Chart/Issue2506Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function writeCharts(XlsxWriter $writer): void
public function testDataSeriesValues(): void
{
$reader = new XlsxReader();
self::readCharts($reader);
$this->readCharts($reader);
$spreadsheet = $reader->load(self::DIRECTORY . 'issue.2506.xlsx');
$worksheet = $spreadsheet->getActiveSheet();
$charts = $worksheet->getChartCollection();
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpSpreadsheetTests/Chart/MultiplierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Chart;

use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Properties;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
Expand Down Expand Up @@ -109,7 +109,7 @@ public function testMultiplier(): void
'ky' => null,
],
'color' => [
'type' => Properties::EXCEL_COLOR_TYPE_ARGB,
'type' => ChartColor::EXCEL_COLOR_TYPE_RGB,
'value' => 'FF0000',
'alpha' => 20,
],
Expand Down
Loading