Phpstan and Xlsx Reader (#3043)

Eliminate most Phpstan messages in Xlsx Reader. In combination with similar changes to Xlsx Writer, baseline will shrink to just over 3,000 lines.
This commit is contained in:
oleibman 2022-09-04 10:43:31 -07:00 committed by GitHub
parent 57a72037b5
commit adbda63912
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 146 additions and 131 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Chart\Axis as ChartAxis;
use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
@ -121,12 +121,12 @@ $dataSeriesValues[2] // triangle border
$dataSeriesValues[2]->setScatterLines(false); // points not connected $dataSeriesValues[2]->setScatterLines(false); // points not connected
// Added so that Xaxis shows dates instead of Excel-equivalent-year1900-numbers // 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 );
$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true); $xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true);
$xAxis->setAxisOption('textRotation', '45'); $xAxis->setAxisOption('textRotation', '45');
$yAxis = new Axis(); $yAxis = new ChartAxis();
$yAxis->setLineStyleProperties( $yAxis->setLineStyleProperties(
2.5, // width in points 2.5, // width in points
Properties::LINE_STYLE_COMPOUND_SIMPLE, Properties::LINE_STYLE_COMPOUND_SIMPLE,

View File

@ -1,6 +1,6 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Chart\Axis as ChartAxis;
use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
@ -121,13 +121,13 @@ $dataSeriesValues[2] // triangle border
$dataSeriesValues[2]->setScatterLines(false); // points not connected $dataSeriesValues[2]->setScatterLines(false); // points not connected
// Added so that Xaxis shows dates instead of Excel-equivalent-year1900-numbers // 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 );
$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true); $xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true);
$xAxis->setAxisOption('textRotation', '45'); $xAxis->setAxisOption('textRotation', '45');
$xAxis->setAxisOption('hidden', '1'); $xAxis->setAxisOption('hidden', '1');
$yAxis = new Axis(); $yAxis = new ChartAxis();
$yAxis->setLineStyleProperties( $yAxis->setLineStyleProperties(
2.5, // width in points 2.5, // width in points
Properties::LINE_STYLE_COMPOUND_SIMPLE, Properties::LINE_STYLE_COMPOUND_SIMPLE,

View File

@ -1,6 +1,6 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Chart\Axis as ChartAxis;
use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
@ -77,10 +77,10 @@ $dataSeriesValues = [
// marker details // marker details
$dataSeriesValues[0] $dataSeriesValues[0]
->getMarkerFillColor() ->getMarkerFillColor()
->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_ARGB); ->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
$dataSeriesValues[0] $dataSeriesValues[0]
->getMarkerBorderColor() ->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 // line details - dashed, smooth line (Bezier) with arrows, 40% transparent
$dataSeriesValues[0] $dataSeriesValues[0]
@ -105,24 +105,24 @@ $dataSeriesValues[1] // square marker border color
->setColorProperties('accent6', 3, ChartColor::EXCEL_COLOR_TYPE_SCHEME); ->setColorProperties('accent6', 3, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
$dataSeriesValues[1] // square marker fill color $dataSeriesValues[1] // square marker fill color
->getMarkerFillColor() ->getMarkerFillColor()
->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB); ->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
$dataSeriesValues[1] $dataSeriesValues[1]
->setScatterLines(true) ->setScatterLines(true)
->setSmoothLine(false) ->setSmoothLine(false)
->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_ARGB); ->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_RGB);
$dataSeriesValues[1]->setLineWidth(2.0); $dataSeriesValues[1]->setLineWidth(2.0);
// series 3 - metric3, markers, no line // series 3 - metric3, markers, no line
$dataSeriesValues[2] // triangle? fill $dataSeriesValues[2] // triangle? fill
//->setPointMarker('triangle') // let Excel choose shape, which is predicted to be a triangle //->setPointMarker('triangle') // let Excel choose shape, which is predicted to be a triangle
->getMarkerFillColor() ->getMarkerFillColor()
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB); ->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
$dataSeriesValues[2] // triangle border $dataSeriesValues[2] // triangle border
->getMarkerBorderColor() ->getMarkerBorderColor()
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME); ->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
$dataSeriesValues[2]->setScatterLines(false); // points not connected $dataSeriesValues[2]->setScatterLines(false); // points not connected
// Added so that Xaxis shows dates instead of Excel-equivalent-year1900-numbers // 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); $xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true);
// Build the dataseries // Build the dataseries
@ -204,7 +204,7 @@ $dataSeriesValues[0]->setTrendLines($trendLines);
$dataSeriesValues[0]->setScatterLines(false); // points not connected $dataSeriesValues[0]->setScatterLines(false); // points not connected
$dataSeriesValues[0]->getMarkerFillColor() $dataSeriesValues[0]->getMarkerFillColor()
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB); ->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
$dataSeriesValues[0]->getMarkerBorderColor() $dataSeriesValues[0]->getMarkerBorderColor()
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME); ->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
@ -218,7 +218,7 @@ $dataSeriesValues[0]->getTrendLines()[1]->setLineStyleProperties(1.25);
$dataSeriesValues[0]->getTrendLines()[2]->getLineColor()->setColorProperties('accent2', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME); $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); $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 $xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601); // m/d/yyyy
// Build the dataseries // Build the dataseries

View File

@ -324,13 +324,13 @@ class DataSeriesValues extends Properties
if (is_array($this->fillColor)) { if (is_array($this->fillColor)) {
$array = []; $array = [];
foreach ($this->fillColor as $chartColor) { foreach ($this->fillColor as $chartColor) {
$array[] = self::chartColorToString($chartColor); $array[] = $this->chartColorToString($chartColor);
} }
return $array; return $array;
} }
return self::chartColorToString($this->fillColor); return $this->chartColorToString($this->fillColor);
} }
/** /**
@ -348,13 +348,13 @@ class DataSeriesValues extends Properties
if ($fillString instanceof ChartColor) { if ($fillString instanceof ChartColor) {
$this->fillColor[] = $fillString; $this->fillColor[] = $fillString;
} else { } else {
$this->fillColor[] = self::stringToChartColor($fillString); $this->fillColor[] = $this->stringToChartColor($fillString);
} }
} }
} elseif ($color instanceof ChartColor) { } elseif ($color instanceof ChartColor) {
$this->fillColor = $color; $this->fillColor = $color;
} elseif (is_string($color)) { } else {
$this->fillColor = self::stringToChartColor($color); $this->fillColor = $this->stringToChartColor($color);
} }
return $this; return $this;

View File

@ -311,7 +311,7 @@ class Chart
break; break;
case 'stockChart': case 'stockChart':
$plotSeries[] = $this->chartDataSeries($chartDetail, $chartDetailKey); $plotSeries[] = $this->chartDataSeries($chartDetail, $chartDetailKey);
$plotAttributes = $this->readChartAttributes($plotAreaLayout); $plotAttributes = $this->readChartAttributes($chartDetail);
break; break;
} }
@ -1068,7 +1068,7 @@ class Chart
} }
/** /**
* @param null|Layout|SimpleXMLElement $chartDetail * @param ?SimpleXMLElement $chartDetail
*/ */
private function readChartAttributes($chartDetail): array private function readChartAttributes($chartDetail): array
{ {

View File

@ -349,7 +349,7 @@ class Font
// Special case if there are one or more newline characters ("\n") // Special case if there are one or more newline characters ("\n")
$cellText = $cellText ?? ''; $cellText = $cellText ?? '';
if (strpos($cellText, "\n") !== false) { if (strpos(/** @scrutinizer ignore-type */ $cellText, "\n") !== false) {
$lineTexts = explode("\n", $cellText); $lineTexts = explode("\n", $cellText);
$lineWidths = []; $lineWidths = [];
foreach ($lineTexts as $lineText) { foreach ($lineTexts as $lineText) {

View File

@ -337,9 +337,19 @@ class StringHelper
mb_substitute_character(65533); // Unicode substitution character mb_substitute_character(65533); // Unicode substitution character
// Phpstan does not think this can return false. // Phpstan does not think this can return false.
$returnValue = mb_convert_encoding($textValue, 'UTF-8', 'UTF-8'); $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 : '';
} }
/** /**
@ -433,7 +443,7 @@ class StringHelper
} }
} }
return mb_convert_encoding($textValue, $to, $from); return self::returnString(mb_convert_encoding($textValue, $to, $from));
} }
/** /**

View File

@ -743,14 +743,14 @@ class Font extends Supervisor
private function hashChartColor(?ChartColor $underlineColor): string private function hashChartColor(?ChartColor $underlineColor): string
{ {
if ($this->underlineColor === null) { if ($underlineColor === null) {
return ''; return '';
} }
return return
$this->underlineColor->getValue() $underlineColor->getValue()
. $this->underlineColor->getType() . $underlineColor->getType()
. (string) $this->underlineColor->getAlpha(); . (string) $underlineColor->getAlpha();
} }
/** /**

View File

@ -33,9 +33,6 @@ class Dompdf extends Pdf
{ {
$fileHandle = parent::prepareForSave($filename); $fileHandle = parent::prepareForSave($filename);
// Default PDF paper size
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)
// Check for paper size and page orientation // Check for paper size and page orientation
$setup = $this->spreadsheet->getSheet($this->getSheetIndex() ?? 0)->getPageSetup(); $setup = $this->spreadsheet->getSheet($this->getSheetIndex() ?? 0)->getPageSetup();
$orientation = $this->getOrientation() ?? $setup->getOrientation(); $orientation = $this->getOrientation() ?? $setup->getOrientation();

View File

@ -233,8 +233,6 @@ class Chart extends WriterPart
if ($plotArea === null) { if ($plotArea === null) {
return; return;
} }
$majorGridlines = ($yAxis === null) ? null : $yAxis->getMajorGridlines();
$minorGridlines = ($yAxis === null) ? null : $yAxis->getMinorGridlines();
$id1 = $id2 = $id3 = '0'; $id1 = $id2 = $id3 = '0';
$this->seriesIndex = 0; $this->seriesIndex = 0;
@ -1163,7 +1161,6 @@ class Chart extends WriterPart
$intercept = $trendLine->getIntercept(); $intercept = $trendLine->getIntercept();
$name = $trendLine->getName(); $name = $trendLine->getName();
$trendLineColor = $trendLine->getLineColor(); // ChartColor $trendLineColor = $trendLine->getLineColor(); // ChartColor
$trendLineWidth = $trendLine->getLineStyleProperty('width');
$objWriter->startElement('c:trendline'); // N.B. lowercase 'ell' $objWriter->startElement('c:trendline'); // N.B. lowercase 'ell'
if ($name !== '') { if ($name !== '') {

View File

@ -12,7 +12,7 @@ class FormulaParserTest extends TestCase
{ {
$this->expectException(CalcException::class); $this->expectException(CalcException::class);
$this->expectExceptionMessage('Invalid parameter passed: formula'); $this->expectExceptionMessage('Invalid parameter passed: formula');
$result = new FormulaParser(null); new FormulaParser(null);
} }
public function testInvalidTokenId(): void public function testInvalidTokenId(): void

View File

@ -3,11 +3,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Chart; namespace PhpOffice\PhpSpreadsheetTests\Chart;
use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Properties;
use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -107,7 +107,7 @@ class AxisGlowTest extends AbstractFunctional
$yAxis = $chart->getChartAxisY(); $yAxis = $chart->getChartAxisY();
$xAxis = $chart->getChartAxisX(); $xAxis = $chart->getChartAxisX();
$yGlowSize = 10.0; $yGlowSize = 10.0;
$yAxis->setGlowProperties($yGlowSize, 'FFFF00', 30, Properties::EXCEL_COLOR_TYPE_ARGB); $yAxis->setGlowProperties($yGlowSize, 'FFFF00', 30, ChartColor::EXCEL_COLOR_TYPE_RGB);
$expectedGlowColor = [ $expectedGlowColor = [
'type' => 'srgbClr', 'type' => 'srgbClr',
'value' => 'FFFF00', 'value' => 'FFFF00',
@ -231,7 +231,7 @@ class AxisGlowTest extends AbstractFunctional
); );
$yAxis = $chart->getChartAxisX(); // deliberate $yAxis = $chart->getChartAxisX(); // deliberate
$yGlowSize = 20.0; $yGlowSize = 20.0;
$yAxis->setGlowProperties($yGlowSize, 'accent1', 20, Properties::EXCEL_COLOR_TYPE_SCHEME); $yAxis->setGlowProperties($yGlowSize, 'accent1', 20, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
$expectedGlowColor = [ $expectedGlowColor = [
'type' => 'schemeClr', 'type' => 'schemeClr',
'value' => 'accent1', 'value' => 'accent1',

View File

@ -3,11 +3,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Chart; namespace PhpOffice\PhpSpreadsheetTests\Chart;
use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Properties;
use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -113,7 +113,7 @@ class AxisShadowTest extends AbstractFunctional
'distance' => 3, 'distance' => 3,
'rotWithShape' => 0, 'rotWithShape' => 0,
'color' => [ 'color' => [
'type' => Properties::EXCEL_COLOR_TYPE_STANDARD, 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
'value' => 'black', 'value' => 'black',
'alpha' => 40, 'alpha' => 40,
], ],
@ -139,7 +139,7 @@ class AxisShadowTest extends AbstractFunctional
'ky' => null, 'ky' => null,
], ],
'color' => [ 'color' => [
'type' => Properties::EXCEL_COLOR_TYPE_ARGB, 'type' => ChartColor::EXCEL_COLOR_TYPE_RGB,
'value' => 'FF0000', 'value' => 'FF0000',
'alpha' => 20, 'alpha' => 20,
], ],

View File

@ -4,12 +4,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Chart;
use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Chart\Axis;
use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\GridLines; use PhpOffice\PhpSpreadsheet\Chart\GridLines;
use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Properties;
use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -98,7 +98,7 @@ class GridlinesShadowGlowTest extends AbstractFunctional
$majorGridlines = new GridLines(); $majorGridlines = new GridLines();
$yAxis->setMajorGridlines($majorGridlines); $yAxis->setMajorGridlines($majorGridlines);
$majorGlowSize = 10.0; $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; $softEdgeSize = 2.5;
$majorGridlines->setSoftEdges($softEdgeSize); $majorGridlines->setSoftEdges($softEdgeSize);
$expectedGlowColor = [ $expectedGlowColor = [
@ -122,7 +122,7 @@ class GridlinesShadowGlowTest extends AbstractFunctional
'distance' => 3, 'distance' => 3,
'rotWithShape' => 0, 'rotWithShape' => 0,
'color' => [ 'color' => [
'type' => Properties::EXCEL_COLOR_TYPE_STANDARD, 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
'value' => 'black', 'value' => 'black',
'alpha' => 40, 'alpha' => 40,
], ],

View File

@ -23,7 +23,7 @@ class Issue2506Test extends AbstractFunctional
public function testDataSeriesValues(): void public function testDataSeriesValues(): void
{ {
$reader = new XlsxReader(); $reader = new XlsxReader();
self::readCharts($reader); $this->readCharts($reader);
$spreadsheet = $reader->load(self::DIRECTORY . 'issue.2506.xlsx'); $spreadsheet = $reader->load(self::DIRECTORY . 'issue.2506.xlsx');
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$charts = $worksheet->getChartCollection(); $charts = $worksheet->getChartCollection();

View File

@ -3,11 +3,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Chart; namespace PhpOffice\PhpSpreadsheetTests\Chart;
use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Properties;
use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\Shared\File; use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -109,7 +109,7 @@ class MultiplierTest extends TestCase
'ky' => null, 'ky' => null,
], ],
'color' => [ 'color' => [
'type' => Properties::EXCEL_COLOR_TYPE_ARGB, 'type' => ChartColor::EXCEL_COLOR_TYPE_RGB,
'value' => 'FF0000', 'value' => 'FF0000',
'alpha' => 20, 'alpha' => 20,
], ],

View File

@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Chart; namespace PhpOffice\PhpSpreadsheetTests\Chart;
use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Chart\Axis;
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
use PhpOffice\PhpSpreadsheet\Chart\GridLines; use PhpOffice\PhpSpreadsheet\Chart\GridLines;
use PhpOffice\PhpSpreadsheet\Chart\Properties; use PhpOffice\PhpSpreadsheet\Chart\Properties;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -131,7 +132,7 @@ class ShadowPresetsTest extends TestCase
'presets' => Properties::SHADOW_PRESETS_NOSHADOW, 'presets' => Properties::SHADOW_PRESETS_NOSHADOW,
'effect' => null, 'effect' => null,
'color' => [ 'color' => [
'type' => Properties::EXCEL_COLOR_TYPE_STANDARD, 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
'value' => 'black', 'value' => 'black',
'alpha' => 40, 'alpha' => 40,
], ],
@ -160,7 +161,7 @@ class ShadowPresetsTest extends TestCase
'presets' => Properties::SHADOW_PRESETS_NOSHADOW, 'presets' => Properties::SHADOW_PRESETS_NOSHADOW,
'effect' => null, 'effect' => null,
'color' => [ 'color' => [
'type' => Properties::EXCEL_COLOR_TYPE_STANDARD, 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
'value' => 'black', 'value' => 'black',
'alpha' => 40, 'alpha' => 40,
], ],
@ -189,7 +190,7 @@ class ShadowPresetsTest extends TestCase
'presets' => Properties::SHADOW_PRESETS_NOSHADOW, 'presets' => Properties::SHADOW_PRESETS_NOSHADOW,
'effect' => null, 'effect' => null,
'color' => [ 'color' => [
'type' => Properties::EXCEL_COLOR_TYPE_STANDARD, 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
'value' => 'black', 'value' => 'black',
'alpha' => 40, 'alpha' => 40,
], ],

View File

@ -11,14 +11,16 @@ class AutoFilter2Test extends TestCase
{ {
private const TESTBOOK = 'tests/data/Reader/XLSX/autofilter2.xlsx'; private const TESTBOOK = 'tests/data/Reader/XLSX/autofilter2.xlsx';
public function getVisibleSheet(Worksheet $sheet, int $maxRow): array public function getVisibleSheet(?Worksheet $sheet, int $maxRow): array
{ {
$actualVisible = []; $actualVisible = [];
if ($sheet !== null) {
for ($row = 2; $row <= $maxRow; ++$row) { for ($row = 2; $row <= $maxRow; ++$row) {
if ($sheet->getRowDimension($row)->getVisible()) { if ($sheet->getRowDimension($row)->getVisible()) {
$actualVisible[] = $row; $actualVisible[] = $row;
} }
} }
}
return $actualVisible; return $actualVisible;
} }
@ -35,13 +37,14 @@ class AutoFilter2Test extends TestCase
self::assertCount(1, $columns); self::assertCount(1, $columns);
$column = $columns['A'] ?? null; $column = $columns['A'] ?? null;
self::assertNotNull($column); self::assertNotNull($column);
/** @scrutinizer ignore-call */
$ruleset = $column->getRules(); $ruleset = $column->getRules();
self::assertCount(1, $ruleset); self::assertCount(1, $ruleset);
$rule = $ruleset[0]; $rule = $ruleset[0];
self::assertSame(Rule::AUTOFILTER_RULETYPE_DATEGROUP, $rule->getRuleType()); self::assertSame(Rule::AUTOFILTER_RULETYPE_DATEGROUP, $rule->getRuleType());
$value = $rule->getValue(); $value = $rule->getValue();
self::assertIsArray($value); self::assertIsArray($value);
self::assertCount(6, $value); self::assertCount(6, /** @scrutinizer ignore-type */ $value);
self::assertSame('2002', $value['year']); self::assertSame('2002', $value['year']);
self::assertSame('', $value['month']); self::assertSame('', $value['month']);
self::assertSame('', $value['day']); self::assertSame('', $value['day']);

View File

@ -24,14 +24,14 @@ class RibbonTest extends AbstractFunctional
self::assertSame('customUI/customUI.xml', $target); self::assertSame('customUI/customUI.xml', $target);
$data = $spreadsheet->getRibbonXMLData('data'); $data = $spreadsheet->getRibbonXMLData('data');
self::assertIsString($data); self::assertIsString($data);
self::assertSame(1522, strlen($data)); self::assertSame(1522, strlen(/** @scrutinizer ignore-type */ $data));
$vbaCode = (string) $spreadsheet->getMacrosCode(); $vbaCode = (string) $spreadsheet->getMacrosCode();
self::assertSame(13312, strlen($vbaCode)); self::assertSame(13312, strlen($vbaCode));
self::assertNull($spreadsheet->getRibbonBinObjects()); self::assertNull($spreadsheet->getRibbonBinObjects());
self::assertNull($spreadsheet->getRibbonBinObjects('names')); foreach (['names', 'data', 'xxxxx'] as $type) {
self::assertNull($spreadsheet->getRibbonBinObjects('data')); self::assertNull($spreadsheet->getRibbonBinObjects($type), "Expecting null when type is $type");
}
self::assertEmpty($spreadsheet->getRibbonBinObjects('types')); self::assertEmpty($spreadsheet->getRibbonBinObjects('types'));
self::assertNull($spreadsheet->getRibbonBinObjects('xxxxx'));
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx'); $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
$spreadsheet->disconnectWorksheets(); $spreadsheet->disconnectWorksheets();
@ -58,7 +58,7 @@ class RibbonTest extends AbstractFunctional
self::assertSame('customUI/customUI.xml', $target); self::assertSame('customUI/customUI.xml', $target);
$data = $spreadsheet->getRibbonXMLData('data'); $data = $spreadsheet->getRibbonXMLData('data');
self::assertIsString($data); self::assertIsString($data);
self::assertSame(1522, strlen($data)); self::assertSame(1522, strlen(/** @scrutinizer ignore-type */ $data));
$vbaCode = (string) $spreadsheet->getMacrosCode(); $vbaCode = (string) $spreadsheet->getMacrosCode();
self::assertSame(13312, strlen($vbaCode)); self::assertSame(13312, strlen($vbaCode));
$spreadsheet->discardMacros(); $spreadsheet->discardMacros();

View File

@ -28,7 +28,9 @@ class RichTextTest extends TestCase
public function testTextElements(): void public function testTextElements(): void
{ {
$element1 = new TextElement('A'); $element1 = new TextElement('A');
self::assertNull($element1->getFont()); if ($element1->getFont() !== null) {
self::fail('Expected font to be null');
}
$element2 = new TextElement('B'); $element2 = new TextElement('B');
$element3 = new TextElement('C'); $element3 = new TextElement('C');
$richText = new RichText(); $richText = new RichText();

View File

@ -9,81 +9,93 @@ use PHPUnit\Framework\TestCase;
class SpreadsheetCoverageTest extends TestCase class SpreadsheetCoverageTest extends TestCase
{ {
/** @var ?Spreadsheet */
private $spreadsheet;
/** @var ?Spreadsheet */
private $spreadsheet2;
protected function tearDown(): void
{
if ($this->spreadsheet !== null) {
$this->spreadsheet->disconnectWorksheets();
$this->spreadsheet = null;
}
if ($this->spreadsheet2 !== null) {
$this->spreadsheet2->disconnectWorksheets();
$this->spreadsheet2 = null;
}
}
public function testDocumentProperties(): void public function testDocumentProperties(): void
{ {
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$properties = $spreadsheet->getProperties(); $properties = $this->spreadsheet->getProperties();
$properties->setCreator('Anyone'); $properties->setCreator('Anyone');
$properties->setTitle('Description'); $properties->setTitle('Description');
$spreadsheet2 = new Spreadsheet(); $this->spreadsheet2 = new Spreadsheet();
self::assertNotEquals($properties, $spreadsheet2->getProperties()); self::assertNotEquals($properties, $this->spreadsheet2->getProperties());
$properties2 = clone $properties; $properties2 = clone $properties;
$spreadsheet2->setProperties($properties2); $this->spreadsheet2->setProperties($properties2);
self::assertEquals($properties, $spreadsheet2->getProperties()); self::assertEquals($properties, $this->spreadsheet2->getProperties());
$spreadsheet->disconnectWorksheets();
$spreadsheet2->disconnectWorksheets();
} }
public function testDocumentSecurity(): void public function testDocumentSecurity(): void
{ {
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$security = $spreadsheet->getSecurity(); $security = $this->spreadsheet->getSecurity();
$security->setLockRevision(true); $security->setLockRevision(true);
$revisionsPassword = 'revpasswd'; $revisionsPassword = 'revpasswd';
$security->setRevisionsPassword($revisionsPassword); $security->setRevisionsPassword($revisionsPassword);
$spreadsheet2 = new Spreadsheet(); $this->spreadsheet2 = new Spreadsheet();
self::assertNotEquals($security, $spreadsheet2->getSecurity()); self::assertNotEquals($security, $this->spreadsheet2->getSecurity());
$security2 = clone $security; $security2 = clone $security;
$spreadsheet2->setSecurity($security2); $this->spreadsheet2->setSecurity($security2);
self::assertEquals($security, $spreadsheet2->getSecurity()); self::assertEquals($security, $this->spreadsheet2->getSecurity());
$spreadsheet->disconnectWorksheets();
$spreadsheet2->disconnectWorksheets();
} }
public function testCellXfCollection(): void public function testCellXfCollection(): void
{ {
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $this->spreadsheet->getActiveSheet();
$sheet->getStyle('A1')->getFont()->setName('font1'); $sheet->getStyle('A1')->getFont()->setName('font1');
$sheet->getStyle('A2')->getFont()->setName('font2'); $sheet->getStyle('A2')->getFont()->setName('font2');
$sheet->getStyle('A3')->getFont()->setName('font3'); $sheet->getStyle('A3')->getFont()->setName('font3');
$sheet->getStyle('B1')->getFont()->setName('font1'); $sheet->getStyle('B1')->getFont()->setName('font1');
$sheet->getStyle('B2')->getFont()->setName('font2'); $sheet->getStyle('B2')->getFont()->setName('font2');
$collection = $spreadsheet->getCellXfCollection(); $collection = $this->spreadsheet->getCellXfCollection();
self::assertCount(4, $collection); self::assertCount(4, $collection);
$font1Style = $collection[1]; $font1Style = $collection[1];
self::assertTrue($spreadsheet->cellXfExists($font1Style)); self::assertTrue($this->spreadsheet->cellXfExists($font1Style));
self::assertSame('font1', $spreadsheet->getCellXfCollection()[1]->getFont()->getName()); self::assertSame('font1', $this->spreadsheet->getCellXfCollection()[1]->getFont()->getName());
self::assertSame('font1', $sheet->getStyle('A1')->getFont()->getName()); self::assertSame('font1', $sheet->getStyle('A1')->getFont()->getName());
self::assertSame('font2', $sheet->getStyle('A2')->getFont()->getName()); self::assertSame('font2', $sheet->getStyle('A2')->getFont()->getName());
self::assertSame('font3', $sheet->getStyle('A3')->getFont()->getName()); self::assertSame('font3', $sheet->getStyle('A3')->getFont()->getName());
self::assertSame('font1', $sheet->getStyle('B1')->getFont()->getName()); self::assertSame('font1', $sheet->getStyle('B1')->getFont()->getName());
self::assertSame('font2', $sheet->getStyle('B2')->getFont()->getName()); self::assertSame('font2', $sheet->getStyle('B2')->getFont()->getName());
$spreadsheet->removeCellXfByIndex(1); $this->spreadsheet->removeCellXfByIndex(1);
self::assertFalse($spreadsheet->cellXfExists($font1Style)); self::assertFalse($this->spreadsheet->cellXfExists($font1Style));
self::assertSame('font2', $spreadsheet->getCellXfCollection()[1]->getFont()->getName()); self::assertSame('font2', $this->spreadsheet->getCellXfCollection()[1]->getFont()->getName());
self::assertSame('Calibri', $sheet->getStyle('A1')->getFont()->getName()); self::assertSame('Calibri', $sheet->getStyle('A1')->getFont()->getName());
self::assertSame('font2', $sheet->getStyle('A2')->getFont()->getName()); self::assertSame('font2', $sheet->getStyle('A2')->getFont()->getName());
self::assertSame('font3', $sheet->getStyle('A3')->getFont()->getName()); self::assertSame('font3', $sheet->getStyle('A3')->getFont()->getName());
self::assertSame('Calibri', $sheet->getStyle('B1')->getFont()->getName()); self::assertSame('Calibri', $sheet->getStyle('B1')->getFont()->getName());
self::assertSame('font2', $sheet->getStyle('B2')->getFont()->getName()); self::assertSame('font2', $sheet->getStyle('B2')->getFont()->getName());
$spreadsheet->disconnectWorksheets();
} }
public function testInvalidRemoveCellXfByIndex(): void public function testInvalidRemoveCellXfByIndex(): void
{ {
$this->expectException(SSException::class); $this->expectException(SSException::class);
$this->expectExceptionMessage('CellXf index is out of bounds.'); $this->expectExceptionMessage('CellXf index is out of bounds.');
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $this->spreadsheet->getActiveSheet();
$sheet->getStyle('A1')->getFont()->setName('font1'); $sheet->getStyle('A1')->getFont()->setName('font1');
$sheet->getStyle('A2')->getFont()->setName('font2'); $sheet->getStyle('A2')->getFont()->setName('font2');
$sheet->getStyle('A3')->getFont()->setName('font3'); $sheet->getStyle('A3')->getFont()->setName('font3');
$sheet->getStyle('B1')->getFont()->setName('font1'); $sheet->getStyle('B1')->getFont()->setName('font1');
$sheet->getStyle('B2')->getFont()->setName('font2'); $sheet->getStyle('B2')->getFont()->setName('font2');
$spreadsheet->removeCellXfByIndex(5); $this->spreadsheet->removeCellXfByIndex(5);
$spreadsheet->disconnectWorksheets();
} }
public function testInvalidRemoveDefaultStyle(): void public function testInvalidRemoveDefaultStyle(): void
@ -91,71 +103,63 @@ class SpreadsheetCoverageTest extends TestCase
$this->expectException(SSException::class); $this->expectException(SSException::class);
$this->expectExceptionMessage('No default style found for this workbook'); $this->expectExceptionMessage('No default style found for this workbook');
// Removing default style probably should be disallowed. // Removing default style probably should be disallowed.
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $this->spreadsheet->removeCellXfByIndex(0);
$spreadsheet->removeCellXfByIndex(0); $this->spreadsheet->getDefaultStyle();
$style = $spreadsheet->getDefaultStyle();
$spreadsheet->disconnectWorksheets();
} }
public function testCellStyleXF(): void public function testCellStyleXF(): void
{ {
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$collection = $spreadsheet->getCellStyleXfCollection(); $collection = $this->spreadsheet->getCellStyleXfCollection();
self::assertCount(1, $collection); self::assertCount(1, $collection);
$styleXf = $collection[0]; $styleXf = $collection[0];
self::assertSame($styleXf, $spreadsheet->getCellStyleXfByIndex(0)); self::assertSame($styleXf, $this->spreadsheet->getCellStyleXfByIndex(0));
$hash = $styleXf->getHashCode(); $hash = $styleXf->getHashCode();
self::assertSame($styleXf, $spreadsheet->getCellStyleXfByHashCode($hash)); self::assertSame($styleXf, $this->spreadsheet->getCellStyleXfByHashCode($hash));
self::assertFalse($spreadsheet->getCellStyleXfByHashCode($hash . 'x')); self::assertFalse($this->spreadsheet->getCellStyleXfByHashCode($hash . 'x'));
$spreadsheet->disconnectWorksheets();
} }
public function testInvalidRemoveCellStyleXfByIndex(): void public function testInvalidRemoveCellStyleXfByIndex(): void
{ {
$this->expectException(SSException::class); $this->expectException(SSException::class);
$this->expectExceptionMessage('CellStyleXf index is out of bounds.'); $this->expectExceptionMessage('CellStyleXf index is out of bounds.');
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $this->spreadsheet->removeCellStyleXfByIndex(5);
$spreadsheet->removeCellStyleXfByIndex(5);
$spreadsheet->disconnectWorksheets();
} }
public function testInvalidFirstSheetIndex(): void public function testInvalidFirstSheetIndex(): void
{ {
$this->expectException(SSException::class); $this->expectException(SSException::class);
$this->expectExceptionMessage('First sheet index must be a positive integer.'); $this->expectExceptionMessage('First sheet index must be a positive integer.');
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$spreadsheet->setFirstSheetIndex(-1); $this->spreadsheet->setFirstSheetIndex(-1);
$spreadsheet->disconnectWorksheets();
} }
public function testInvalidVisibility(): void public function testInvalidVisibility(): void
{ {
$this->expectException(SSException::class); $this->expectException(SSException::class);
$this->expectExceptionMessage('Invalid visibility value.'); $this->expectExceptionMessage('Invalid visibility value.');
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$spreadsheet->setVisibility(Spreadsheet::VISIBILITY_HIDDEN); $this->spreadsheet->setVisibility(Spreadsheet::VISIBILITY_HIDDEN);
self::assertSame(Spreadsheet::VISIBILITY_HIDDEN, $spreadsheet->getVisibility()); self::assertSame(Spreadsheet::VISIBILITY_HIDDEN, $this->spreadsheet->getVisibility());
$spreadsheet->setVisibility(null); $this->spreadsheet->setVisibility(null);
self::assertSame(Spreadsheet::VISIBILITY_VISIBLE, $spreadsheet->getVisibility()); self::assertSame(Spreadsheet::VISIBILITY_VISIBLE, $this->spreadsheet->getVisibility());
$spreadsheet->setVisibility('badvalue'); $this->spreadsheet->setVisibility('badvalue');
$spreadsheet->disconnectWorksheets();
} }
public function testInvalidTabRatio(): void public function testInvalidTabRatio(): void
{ {
$this->expectException(SSException::class); $this->expectException(SSException::class);
$this->expectExceptionMessage('Tab ratio must be between 0 and 1000.'); $this->expectExceptionMessage('Tab ratio must be between 0 and 1000.');
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$spreadsheet->setTabRatio(2000); $this->spreadsheet->setTabRatio(2000);
$spreadsheet->disconnectWorksheets();
} }
public function testCopy(): void public function testCopy(): void
{ {
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $this->spreadsheet->getActiveSheet();
$sheet->getStyle('A1')->getFont()->setName('font1'); $sheet->getStyle('A1')->getFont()->setName('font1');
$sheet->getStyle('A2')->getFont()->setName('font2'); $sheet->getStyle('A2')->getFont()->setName('font2');
$sheet->getStyle('A3')->getFont()->setName('font3'); $sheet->getStyle('A3')->getFont()->setName('font3');
@ -166,8 +170,8 @@ class SpreadsheetCoverageTest extends TestCase
$sheet->getCell('A3')->setValue('this is a3'); $sheet->getCell('A3')->setValue('this is a3');
$sheet->getCell('B1')->setValue('this is b1'); $sheet->getCell('B1')->setValue('this is b1');
$sheet->getCell('B2')->setValue('this is b2'); $sheet->getCell('B2')->setValue('this is b2');
$copied = $spreadsheet->copy(); $this->spreadsheet2 = $this->spreadsheet->copy();
$copysheet = $copied->getActiveSheet(); $copysheet = $this->spreadsheet2->getActiveSheet();
$copysheet->getStyle('A2')->getFont()->setName('font12'); $copysheet->getStyle('A2')->getFont()->setName('font12');
$copysheet->getCell('A2')->setValue('this was a2'); $copysheet->getCell('A2')->setValue('this was a2');
@ -192,18 +196,13 @@ class SpreadsheetCoverageTest extends TestCase
self::assertSame('this is a3', $copysheet->getCell('A3')->getValue()); self::assertSame('this is a3', $copysheet->getCell('A3')->getValue());
self::assertSame('this is b1', $copysheet->getCell('B1')->getValue()); self::assertSame('this is b1', $copysheet->getCell('B1')->getValue());
self::assertSame('this is b2', $copysheet->getCell('B2')->getValue()); self::assertSame('this is b2', $copysheet->getCell('B2')->getValue());
$spreadsheet->disconnectWorksheets();
$copied->disconnectWorksheets();
} }
public function testClone(): void public function testClone(): void
{ {
$this->expectException(SSException::class); $this->expectException(SSException::class);
$this->expectExceptionMessage('Do not use clone on spreadsheet. Use spreadsheet->copy() instead.'); $this->expectExceptionMessage('Do not use clone on spreadsheet. Use spreadsheet->copy() instead.');
$spreadsheet = new Spreadsheet(); $this->spreadsheet = new Spreadsheet();
$clone = clone $spreadsheet; $this->spreadsheet2 = clone $this->spreadsheet;
$spreadsheet->disconnectWorksheets();
$clone->disconnectWorksheets();
} }
} }

View File

@ -40,6 +40,7 @@ class ColumnCellIteratorTest extends TestCase
$values = []; $values = [];
foreach ($iterator as $key => $ColumnCell) { foreach ($iterator as $key => $ColumnCell) {
self::assertNotNull($ColumnCell); self::assertNotNull($ColumnCell);
/** @scrutinizer ignore-call */
$values[] = $ColumnCell->getValue(); $values[] = $ColumnCell->getValue();
self::assertEquals($ColumnCellIndexResult++, $key); self::assertEquals($ColumnCellIndexResult++, $key);
self::assertInstanceOf(Cell::class, $ColumnCell); self::assertInstanceOf(Cell::class, $ColumnCell);
@ -60,6 +61,7 @@ class ColumnCellIteratorTest extends TestCase
$values = []; $values = [];
foreach ($iterator as $key => $ColumnCell) { foreach ($iterator as $key => $ColumnCell) {
self::assertNotNull($ColumnCell); self::assertNotNull($ColumnCell);
/** @scrutinizer ignore-call */
$values[] = $ColumnCell->getValue(); $values[] = $ColumnCell->getValue();
self::assertEquals($ColumnCellIndexResult++, $key); self::assertEquals($ColumnCellIndexResult++, $key);
self::assertInstanceOf(Cell::class, $ColumnCell); self::assertInstanceOf(Cell::class, $ColumnCell);
@ -81,6 +83,7 @@ class ColumnCellIteratorTest extends TestCase
while ($iterator->valid()) { while ($iterator->valid()) {
$current = $iterator->current(); $current = $iterator->current();
self::assertNotNull($current); self::assertNotNull($current);
/** @scrutinizer ignore-call */
$cell = $current->getCoordinate(); $cell = $current->getCoordinate();
$values[] = $sheet->getCell($cell)->getValue(); $values[] = $sheet->getCell($cell)->getValue();
$iterator->prev(); $iterator->prev();

View File

@ -40,6 +40,7 @@ class RowCellIteratorTest extends TestCase
$values = []; $values = [];
foreach ($iterator as $key => $RowCell) { foreach ($iterator as $key => $RowCell) {
self::assertNotNull($RowCell); self::assertNotNull($RowCell);
/** @scrutinizer ignore-call */
$values[] = $RowCell->getValue(); $values[] = $RowCell->getValue();
self::assertEquals($RowCellIndexResult++, $key); self::assertEquals($RowCellIndexResult++, $key);
self::assertInstanceOf(Cell::class, $RowCell); self::assertInstanceOf(Cell::class, $RowCell);
@ -59,6 +60,7 @@ class RowCellIteratorTest extends TestCase
$values = []; $values = [];
foreach ($iterator as $key => $RowCell) { foreach ($iterator as $key => $RowCell) {
self::assertNotNull($RowCell); self::assertNotNull($RowCell);
/** @scrutinizer ignore-call */
$values[] = $RowCell->getValue(); $values[] = $RowCell->getValue();
self::assertEquals($RowCellIndexResult++, $key); self::assertEquals($RowCellIndexResult++, $key);
self::assertInstanceOf(Cell::class, $RowCell); self::assertInstanceOf(Cell::class, $RowCell);
@ -80,6 +82,7 @@ class RowCellIteratorTest extends TestCase
while ($iterator->valid()) { while ($iterator->valid()) {
$current = $iterator->current(); $current = $iterator->current();
self::assertNotNull($current); self::assertNotNull($current);
/** @scrutinizer ignore-call */
$cell = $current->getCoordinate(); $cell = $current->getCoordinate();
$values[] = $sheet->getCell($cell)->getValue(); $values[] = $sheet->getCell($cell)->getValue();
$iterator->prev(); $iterator->prev();