Scrutinizer Changes (#3060)

* Scrutinizer Changes

Scrutinizer appears to be working again. But the PRs that have used it have neither added new issues nor fixed existing ones. This PR should fix some exisiting; let's see what Scrutinizer does with it.

* Address Some False Positives

In Reader/Xlsx/Chart.
This commit is contained in:
oleibman 2022-09-16 09:16:11 -07:00 committed by GitHub
parent 90422bf1d2
commit b7fa470138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View File

@ -14,6 +14,7 @@ use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Properties as ChartProperties; use PhpOffice\PhpSpreadsheet\Chart\Properties as ChartProperties;
use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\Chart\TrendLine; use PhpOffice\PhpSpreadsheet\Chart\TrendLine;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Style\Font; use PhpOffice\PhpSpreadsheet\Style\Font;
use SimpleXMLElement; use SimpleXMLElement;
@ -94,7 +95,7 @@ class Chart
break; break;
case 'chart': case 'chart':
foreach ($chartElement as $chartDetailsKey => $chartDetails) { foreach ($chartElement as $chartDetailsKey => $chartDetails) {
$chartDetailsC = $chartDetails->children($this->cNamespace); $chartDetails = Xlsx::testSimpleXml($chartDetails);
switch ($chartDetailsKey) { switch ($chartDetailsKey) {
case 'autoTitleDeleted': case 'autoTitleDeleted':
/** @var bool */ /** @var bool */
@ -113,8 +114,8 @@ class Chart
$plotSeries = $plotAttributes = []; $plotSeries = $plotAttributes = [];
$catAxRead = false; $catAxRead = false;
$plotNoFill = false; $plotNoFill = false;
/** @var SimpleXMLElement $chartDetail */
foreach ($chartDetails as $chartDetailKey => $chartDetail) { foreach ($chartDetails as $chartDetailKey => $chartDetail) {
$chartDetail = Xlsx::testSimpleXml($chartDetail);
switch ($chartDetailKey) { switch ($chartDetailKey) {
case 'spPr': case 'spPr':
$possibleNoFill = $chartDetails->spPr->children($this->aNamespace); $possibleNoFill = $chartDetails->spPr->children($this->aNamespace);
@ -122,8 +123,8 @@ class Chart
$plotNoFill = true; $plotNoFill = true;
} }
if (isset($possibleNoFill->gradFill->gsLst)) { if (isset($possibleNoFill->gradFill->gsLst)) {
/** @var SimpleXMLElement $gradient */
foreach ($possibleNoFill->gradFill->gsLst->gs as $gradient) { foreach ($possibleNoFill->gradFill->gsLst->gs as $gradient) {
$gradient = Xlsx::testSimpleXml($gradient);
/** @var float */ /** @var float */
$pos = self::getAttribute($gradient, 'pos', 'float'); $pos = self::getAttribute($gradient, 'pos', 'float');
$gradientArray[] = [ $gradientArray[] = [
@ -348,6 +349,7 @@ class Chart
$legendLayout = null; $legendLayout = null;
$legendOverlay = false; $legendOverlay = false;
foreach ($chartDetails as $chartDetailKey => $chartDetail) { foreach ($chartDetails as $chartDetailKey => $chartDetail) {
$chartDetail = Xlsx::testSimpleXml($chartDetail);
switch ($chartDetailKey) { switch ($chartDetailKey) {
case 'legendPos': case 'legendPos':
$legendPos = self::getAttribute($chartDetail, 'val', 'string'); $legendPos = self::getAttribute($chartDetail, 'val', 'string');
@ -399,11 +401,13 @@ class Chart
$caption = []; $caption = [];
$titleLayout = null; $titleLayout = null;
foreach ($titleDetails as $titleDetailKey => $chartDetail) { foreach ($titleDetails as $titleDetailKey => $chartDetail) {
$chartDetail = Xlsx::testSimpleXml($chartDetail);
switch ($titleDetailKey) { switch ($titleDetailKey) {
case 'tx': case 'tx':
if (isset($chartDetail->rich)) { if (isset($chartDetail->rich)) {
$titleDetails = $chartDetail->rich->children($this->aNamespace); $titleDetails = $chartDetail->rich->children($this->aNamespace);
foreach ($titleDetails as $titleKey => $titleDetail) { foreach ($titleDetails as $titleKey => $titleDetail) {
$titleDetail = Xlsx::testSimpleXml($titleDetail);
switch ($titleKey) { switch ($titleKey) {
case 'p': case 'p':
$titleDetailPart = $titleDetail->children($this->aNamespace); $titleDetailPart = $titleDetail->children($this->aNamespace);
@ -440,6 +444,7 @@ class Chart
} }
$layout = []; $layout = [];
foreach ($details as $detailKey => $detail) { foreach ($details as $detailKey => $detail) {
$detail = Xlsx::testSimpleXml($detail);
$layout[$detailKey] = self::getAttribute($detail, 'val', 'string'); $layout[$detailKey] = self::getAttribute($detail, 'val', 'string');
} }
@ -472,8 +477,8 @@ class Chart
$lineStyle = null; $lineStyle = null;
$labelLayout = null; $labelLayout = null;
$trendLines = []; $trendLines = [];
/** @var SimpleXMLElement $seriesDetail */
foreach ($seriesDetails as $seriesKey => $seriesDetail) { foreach ($seriesDetails as $seriesKey => $seriesDetail) {
$seriesDetail = Xlsx::testSimpleXml($seriesDetail);
switch ($seriesKey) { switch ($seriesKey) {
case 'idx': case 'idx':
$seriesIndex = self::getAttribute($seriesDetail, 'val', 'integer'); $seriesIndex = self::getAttribute($seriesDetail, 'val', 'integer');
@ -786,6 +791,7 @@ class Chart
$pointCount = 0; $pointCount = 0;
foreach ($seriesValueSet as $seriesValueIdx => $seriesValue) { foreach ($seriesValueSet as $seriesValueIdx => $seriesValue) {
$seriesValue = Xlsx::testSimpleXml($seriesValue);
switch ($seriesValueIdx) { switch ($seriesValueIdx) {
case 'ptCount': case 'ptCount':
$pointCount = self::getAttribute($seriesValue, 'val', 'integer'); $pointCount = self::getAttribute($seriesValue, 'val', 'integer');
@ -858,7 +864,6 @@ class Chart
private function parseRichText(SimpleXMLElement $titleDetailPart): RichText private function parseRichText(SimpleXMLElement $titleDetailPart): RichText
{ {
$value = new RichText(); $value = new RichText();
$objText = null;
$defaultFontSize = null; $defaultFontSize = null;
$defaultBold = null; $defaultBold = null;
$defaultItalic = null; $defaultItalic = null;

View File

@ -1461,9 +1461,6 @@ class Html extends BaseWriter
foreach ($values as $cellAddress) { foreach ($values as $cellAddress) {
[$cell, $cssClass, $coordinate] = $this->generateRowCellCss($worksheet, $cellAddress, $row, $colNum); [$cell, $cssClass, $coordinate] = $this->generateRowCellCss($worksheet, $cellAddress, $row, $colNum);
$colSpan = 1;
$rowSpan = 1;
// Cell Data // Cell Data
$cellData = $this->generateRowCellData($worksheet, $cell, $cssClass, $cellType); $cellData = $this->generateRowCellData($worksheet, $cell, $cssClass, $cellType);

View File

@ -93,6 +93,7 @@ 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];