Reader/Gnumeric vs. Scrutinizer

Just reviewing Scrutinizer's list of "bugs". There are 19 ascribed to me. For some, I will definitely take no action (e.g. use of bitwise operators in AND, OR, and XOR functions). However, where I can clean things up so that Scrutinizer is satisfied and the resulting code is not too contorted, I will make an attempt.

I believe this is the only one with which will involve more than 2 or 3 changes. It fixes 5 items ascribed to me, and 4 to others.
This commit is contained in:
Owen Leibman 2021-06-22 07:09:45 -07:00 committed by Mark Baker
parent 257204d8bc
commit ab26cbcb6d
1 changed files with 11 additions and 7 deletions

View File

@ -266,9 +266,10 @@ class Gnumeric extends BaseReader
(new Properties($this->spreadsheet))->readProperties($xml, $gnmXML); (new Properties($this->spreadsheet))->readProperties($xml, $gnmXML);
$worksheetID = 0; $worksheetID = 0;
foreach ($gnmXML->Sheets->Sheet as $sheet) { foreach ($gnmXML->Sheets->Sheet as $sheetOrNull) {
$sheet = self::testSimpleXml($sheetOrNull);
$worksheetName = (string) $sheet->Name; $worksheetName = (string) $sheet->Name;
if ((isset($this->loadSheetsOnly)) && (!in_array($worksheetName, $this->loadSheetsOnly))) { if (is_array($this->loadSheetsOnly) && !in_array($worksheetName, $this->loadSheetsOnly)) {
continue; continue;
} }
@ -288,8 +289,9 @@ class Gnumeric extends BaseReader
->sheetMargins($sheet); ->sheetMargins($sheet);
} }
foreach ($sheet->Cells->Cell as $cell) { foreach ($sheet->Cells->Cell as $cellOrNull) {
$cellAttributes = $cell->attributes(); $cell = self::testSimpleXml($cellOrNull);
$cellAttributes = self::testSimpleXml($cell->attributes());
$row = (int) $cellAttributes->Row + 1; $row = (int) $cellAttributes->Row + 1;
$column = (int) $cellAttributes->Col; $column = (int) $cellAttributes->Col;
@ -367,7 +369,7 @@ class Gnumeric extends BaseReader
// Handle Merged Cells in this worksheet // Handle Merged Cells in this worksheet
if ($sheet !== null && isset($sheet->MergedRegions)) { if ($sheet !== null && isset($sheet->MergedRegions)) {
foreach ($sheet->MergedRegions->Merge as $mergeCells) { foreach ($sheet->MergedRegions->Merge as $mergeCells) {
if (strpos($mergeCells, ':') !== false) { if (strpos((string) $mergeCells, ':') !== false) {
$this->spreadsheet->getActiveSheet()->mergeCells($mergeCells); $this->spreadsheet->getActiveSheet()->mergeCells($mergeCells);
} }
} }
@ -404,8 +406,9 @@ class Gnumeric extends BaseReader
} }
} }
private function processColumnLoop(int $whichColumn, int $maxCol, SimpleXMLElement $columnOverride, float $defaultWidth): int private function processColumnLoop(int $whichColumn, int $maxCol, ?SimpleXMLElement $columnOverride, float $defaultWidth): int
{ {
$columnOverride = self::testSimpleXml($columnOverride);
$columnAttributes = self::testSimpleXml($columnOverride->attributes()); $columnAttributes = self::testSimpleXml($columnOverride->attributes());
$column = $columnAttributes['No']; $column = $columnAttributes['No'];
$columnWidth = ((float) $columnAttributes['Unit']) / 5.4; $columnWidth = ((float) $columnAttributes['Unit']) / 5.4;
@ -462,8 +465,9 @@ class Gnumeric extends BaseReader
} }
} }
private function processRowLoop(int $whichRow, int $maxRow, SimpleXMLElement $rowOverride, float $defaultHeight): int private function processRowLoop(int $whichRow, int $maxRow, ?SimpleXMLElement $rowOverride, float $defaultHeight): int
{ {
$rowOverride = self::testSimpleXml($rowOverride);
$rowAttributes = self::testSimpleXml($rowOverride->attributes()); $rowAttributes = self::testSimpleXml($rowOverride->attributes());
$row = $rowAttributes['No']; $row = $rowAttributes['No'];
$rowHeight = (float) $rowAttributes['Unit']; $rowHeight = (float) $rowAttributes['Unit'];