Resolve Phpstan Messages in Writer Ods (#3342)

* Resolve Phpstan Messages in Writer Ods

Reduce number of Phpstan messages by addressing their issues.

* Minor Fix

Phpstan reports one fewer error under Php8 than previously.
This commit is contained in:
oleibman
2023-02-05 18:54:11 -08:00
committed by GitHub
parent 8841906dae
commit 14fd9bddeb
6 changed files with 11 additions and 55 deletions
-35
View File
@@ -595,41 +595,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Shared/Trend/Trend.php
-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Ods.php
-
message: "#^If condition is always true\\.$#"
count: 2
path: src/PhpSpreadsheet/Writer/Ods/Cell/Style.php
-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Ods\\\\Cell\\\\Style\\:\\:\\$writer has no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Ods/Cell/Style.php
-
message: "#^Parameter \\#1 \\$range of static method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Coordinate\\:\\:splitRange\\(\\) expects string, string\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Ods/Content.php
-
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int\\<2, max\\> given\\.$#"
count: 3
path: src/PhpSpreadsheet/Writer/Ods/Content.php
-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Ods\\\\Content\\:\\:\\$formulaConvertor has no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Ods/Content.php
-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Ods\\\\Formula\\:\\:\\$definedNames has no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Ods/Formula.php
-
message: "#^Cannot use array destructuring on array\\|false\\.$#"
count: 1
+1 -1
View File
@@ -79,7 +79,7 @@ if (PHP_VERSION_ID < 80000) {
$config['parameters']['ignoreErrors'][] = [
'message' => '#^Binary operation "/" between float and array[|]float[|]int[|]string results in an error.#',
'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php',
'count' => 2,
'count' => 1,
];
}
+1 -9
View File
@@ -117,10 +117,6 @@ class Ods extends BaseWriter
*/
public function save($filename, int $flags = 0): void
{
if (!$this->spreadSheet) {
throw new WriterException('PhpSpreadsheet object unassigned.');
}
$this->processFlags($flags);
// garbage collect
@@ -176,11 +172,7 @@ class Ods extends BaseWriter
*/
public function getSpreadsheet()
{
if ($this->spreadSheet !== null) {
return $this->spreadSheet;
}
throw new WriterException('No PhpSpreadsheet assigned.');
return $this->spreadSheet;
}
/**
+3 -6
View File
@@ -19,6 +19,7 @@ class Style
public const ROW_STYLE_PREFIX = 'ro';
public const TABLE_STYLE_PREFIX = 'ta';
/** @var XMLWriter */
private $writer;
public function __construct(XMLWriter $writer)
@@ -97,9 +98,7 @@ class Style
$this->writer->writeAttribute('style:rotation-align', 'none');
// Fill
if ($fill = $style->getFill()) {
$this->writeFillStyle($fill);
}
$this->writeFillStyle($style->getFill());
$this->writer->endElement();
@@ -142,9 +141,7 @@ class Style
$this->writer->writeAttribute('fo:font-style', 'italic');
}
if ($color = $font->getColor()) {
$this->writer->writeAttribute('fo:color', sprintf('#%s', $color->getRGB()));
}
$this->writer->writeAttribute('fo:color', sprintf('#%s', $font->getColor()->getRGB()));
if ($family = $font->getName()) {
$this->writer->writeAttribute('fo:font-family', $family);
+5 -4
View File
@@ -23,6 +23,7 @@ class Content extends WriterPart
const NUMBER_COLS_REPEATED_MAX = 1024;
const NUMBER_ROWS_REPEATED_MAX = 1048576;
/** @var Formula */
private $formulaConvertor;
/**
@@ -155,7 +156,7 @@ class Content extends WriterPart
$objWriter->startElement('table:table-row');
if ($span_row) {
if ($span_row > 1) {
$objWriter->writeAttribute('table:number-rows-repeated', $span_row);
$objWriter->writeAttribute('table:number-rows-repeated', (string) $span_row);
}
$objWriter->startElement('table:table-cell');
$objWriter->writeAttribute('table:number-columns-repeated', (string) self::NUMBER_COLS_REPEATED_MAX);
@@ -254,7 +255,7 @@ class Content extends WriterPart
if ($numberColsRepeated > 0) {
if ($numberColsRepeated > 1) {
$objWriter->startElement('table:table-cell');
$objWriter->writeAttribute('table:number-columns-repeated', $numberColsRepeated);
$objWriter->writeAttribute('table:number-columns-repeated', (string) $numberColsRepeated);
$objWriter->endElement();
} else {
$objWriter->writeElement('table:table-cell');
@@ -275,7 +276,7 @@ class Content extends WriterPart
$objWriter->writeElement('table:table-cell');
} elseif ($diff > 1) {
$objWriter->startElement('table:table-cell');
$objWriter->writeAttribute('table:number-columns-repeated', $diff);
$objWriter->writeAttribute('table:number-columns-repeated', (string) $diff);
$objWriter->endElement();
}
}
@@ -322,7 +323,7 @@ class Content extends WriterPart
return;
}
$mergeRange = Coordinate::splitRange($cell->getMergeRange());
$mergeRange = Coordinate::splitRange((string) $cell->getMergeRange());
[$startCell, $endCell] = $mergeRange[0];
$start = Coordinate::coordinateFromString($startCell);
$end = Coordinate::coordinateFromString($endCell);
@@ -7,6 +7,7 @@ use PhpOffice\PhpSpreadsheet\DefinedName;
class Formula
{
/** @var array */
private $definedNames = [];
/**