Skip to content

Commit 14fd9bd

Browse files
authored
Resolve Phpstan Messages in Writer Ods (PHPOffice#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.
1 parent 8841906 commit 14fd9bd

File tree

6 files changed

+11
-55
lines changed

6 files changed

+11
-55
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -595,41 +595,6 @@ parameters:
595595
count: 1
596596
path: src/PhpSpreadsheet/Shared/Trend/Trend.php
597597

598-
-
599-
message: "#^Negated boolean expression is always false\\.$#"
600-
count: 1
601-
path: src/PhpSpreadsheet/Writer/Ods.php
602-
603-
-
604-
message: "#^If condition is always true\\.$#"
605-
count: 2
606-
path: src/PhpSpreadsheet/Writer/Ods/Cell/Style.php
607-
608-
-
609-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Ods\\\\Cell\\\\Style\\:\\:\\$writer has no type specified\\.$#"
610-
count: 1
611-
path: src/PhpSpreadsheet/Writer/Ods/Cell/Style.php
612-
613-
-
614-
message: "#^Parameter \\#1 \\$range of static method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Coordinate\\:\\:splitRange\\(\\) expects string, string\\|false given\\.$#"
615-
count: 1
616-
path: src/PhpSpreadsheet/Writer/Ods/Content.php
617-
618-
-
619-
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int\\<2, max\\> given\\.$#"
620-
count: 3
621-
path: src/PhpSpreadsheet/Writer/Ods/Content.php
622-
623-
-
624-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Ods\\\\Content\\:\\:\\$formulaConvertor has no type specified\\.$#"
625-
count: 1
626-
path: src/PhpSpreadsheet/Writer/Ods/Content.php
627-
628-
-
629-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Ods\\\\Formula\\:\\:\\$definedNames has no type specified\\.$#"
630-
count: 1
631-
path: src/PhpSpreadsheet/Writer/Ods/Formula.php
632-
633598
-
634599
message: "#^Cannot use array destructuring on array\\|false\\.$#"
635600
count: 1

phpstan-conditional.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
$config['parameters']['ignoreErrors'][] = [
8080
'message' => '#^Binary operation "/" between float and array[|]float[|]int[|]string results in an error.#',
8181
'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php',
82-
'count' => 2,
82+
'count' => 1,
8383
];
8484
}
8585

src/PhpSpreadsheet/Writer/Ods.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ public function getWriterPartThumbnails(): Thumbnails
117117
*/
118118
public function save($filename, int $flags = 0): void
119119
{
120-
if (!$this->spreadSheet) {
121-
throw new WriterException('PhpSpreadsheet object unassigned.');
122-
}
123-
124120
$this->processFlags($flags);
125121

126122
// garbage collect
@@ -176,11 +172,7 @@ private function createZip()
176172
*/
177173
public function getSpreadsheet()
178174
{
179-
if ($this->spreadSheet !== null) {
180-
return $this->spreadSheet;
181-
}
182-
183-
throw new WriterException('No PhpSpreadsheet assigned.');
175+
return $this->spreadSheet;
184176
}
185177

186178
/**

src/PhpSpreadsheet/Writer/Ods/Cell/Style.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Style
1919
public const ROW_STYLE_PREFIX = 'ro';
2020
public const TABLE_STYLE_PREFIX = 'ta';
2121

22+
/** @var XMLWriter */
2223
private $writer;
2324

2425
public function __construct(XMLWriter $writer)
@@ -97,9 +98,7 @@ private function writeCellProperties(CellStyle $style): void
9798
$this->writer->writeAttribute('style:rotation-align', 'none');
9899

99100
// Fill
100-
if ($fill = $style->getFill()) {
101-
$this->writeFillStyle($fill);
102-
}
101+
$this->writeFillStyle($style->getFill());
103102

104103
$this->writer->endElement();
105104

@@ -142,9 +141,7 @@ protected function writeTextProperties(CellStyle $style): void
142141
$this->writer->writeAttribute('fo:font-style', 'italic');
143142
}
144143

145-
if ($color = $font->getColor()) {
146-
$this->writer->writeAttribute('fo:color', sprintf('#%s', $color->getRGB()));
147-
}
144+
$this->writer->writeAttribute('fo:color', sprintf('#%s', $font->getColor()->getRGB()));
148145

149146
if ($family = $font->getName()) {
150147
$this->writer->writeAttribute('fo:font-family', $family);

src/PhpSpreadsheet/Writer/Ods/Content.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Content extends WriterPart
2323
const NUMBER_COLS_REPEATED_MAX = 1024;
2424
const NUMBER_ROWS_REPEATED_MAX = 1048576;
2525

26+
/** @var Formula */
2627
private $formulaConvertor;
2728

2829
/**
@@ -155,7 +156,7 @@ private function writeRows(XMLWriter $objWriter, Worksheet $sheet, int $sheetInd
155156
$objWriter->startElement('table:table-row');
156157
if ($span_row) {
157158
if ($span_row > 1) {
158-
$objWriter->writeAttribute('table:number-rows-repeated', $span_row);
159+
$objWriter->writeAttribute('table:number-rows-repeated', (string) $span_row);
159160
}
160161
$objWriter->startElement('table:table-cell');
161162
$objWriter->writeAttribute('table:number-columns-repeated', (string) self::NUMBER_COLS_REPEATED_MAX);
@@ -254,7 +255,7 @@ private function writeCells(XMLWriter $objWriter, RowCellIterator $cells): void
254255
if ($numberColsRepeated > 0) {
255256
if ($numberColsRepeated > 1) {
256257
$objWriter->startElement('table:table-cell');
257-
$objWriter->writeAttribute('table:number-columns-repeated', $numberColsRepeated);
258+
$objWriter->writeAttribute('table:number-columns-repeated', (string) $numberColsRepeated);
258259
$objWriter->endElement();
259260
} else {
260261
$objWriter->writeElement('table:table-cell');
@@ -275,7 +276,7 @@ private function writeCellSpan(XMLWriter $objWriter, $curColumn, $prevColumn): v
275276
$objWriter->writeElement('table:table-cell');
276277
} elseif ($diff > 1) {
277278
$objWriter->startElement('table:table-cell');
278-
$objWriter->writeAttribute('table:number-columns-repeated', $diff);
279+
$objWriter->writeAttribute('table:number-columns-repeated', (string) $diff);
279280
$objWriter->endElement();
280281
}
281282
}
@@ -322,7 +323,7 @@ private function writeCellMerge(XMLWriter $objWriter, Cell $cell): void
322323
return;
323324
}
324325

325-
$mergeRange = Coordinate::splitRange($cell->getMergeRange());
326+
$mergeRange = Coordinate::splitRange((string) $cell->getMergeRange());
326327
[$startCell, $endCell] = $mergeRange[0];
327328
$start = Coordinate::coordinateFromString($startCell);
328329
$end = Coordinate::coordinateFromString($endCell);

src/PhpSpreadsheet/Writer/Ods/Formula.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
class Formula
99
{
10+
/** @var array */
1011
private $definedNames = [];
1112

1213
/**

0 commit comments

Comments
 (0)