Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Phpstan Messages in Writer Ods #3342

Merged
merged 3 commits into from Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 0 additions & 35 deletions phpstan-baseline.neon
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion phpstan-conditional.php
Expand Up @@ -79,7 +79,7 @@
$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,
];
}

Expand Down
10 changes: 1 addition & 9 deletions src/PhpSpreadsheet/Writer/Ods.php
Expand Up @@ -117,10 +117,6 @@ public function getWriterPartThumbnails(): Thumbnails
*/
public function save($filename, int $flags = 0): void
{
if (!$this->spreadSheet) {
throw new WriterException('PhpSpreadsheet object unassigned.');
}

$this->processFlags($flags);

// garbage collect
Expand Down Expand Up @@ -176,11 +172,7 @@ private function createZip()
*/
public function getSpreadsheet()
{
if ($this->spreadSheet !== null) {
return $this->spreadSheet;
}

throw new WriterException('No PhpSpreadsheet assigned.');
return $this->spreadSheet;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/PhpSpreadsheet/Writer/Ods/Cell/Style.php
Expand Up @@ -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)
Expand Down Expand Up @@ -97,9 +98,7 @@ private function writeCellProperties(CellStyle $style): void
$this->writer->writeAttribute('style:rotation-align', 'none');

// Fill
if ($fill = $style->getFill()) {
$this->writeFillStyle($fill);
}
$this->writeFillStyle($style->getFill());

$this->writer->endElement();

Expand Down Expand Up @@ -142,9 +141,7 @@ protected function writeTextProperties(CellStyle $style): void
$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);
Expand Down
9 changes: 5 additions & 4 deletions src/PhpSpreadsheet/Writer/Ods/Content.php
Expand Up @@ -23,6 +23,7 @@ class Content extends WriterPart
const NUMBER_COLS_REPEATED_MAX = 1024;
const NUMBER_ROWS_REPEATED_MAX = 1048576;

/** @var Formula */
private $formulaConvertor;

/**
Expand Down Expand Up @@ -155,7 +156,7 @@ private function writeRows(XMLWriter $objWriter, Worksheet $sheet, int $sheetInd
$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);
Expand Down Expand Up @@ -254,7 +255,7 @@ private function writeCells(XMLWriter $objWriter, RowCellIterator $cells): void
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');
Expand All @@ -275,7 +276,7 @@ private function writeCellSpan(XMLWriter $objWriter, $curColumn, $prevColumn): v
$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();
}
}
Expand Down Expand Up @@ -322,7 +323,7 @@ private function writeCellMerge(XMLWriter $objWriter, Cell $cell): void
return;
}

$mergeRange = Coordinate::splitRange($cell->getMergeRange());
$mergeRange = Coordinate::splitRange((string) $cell->getMergeRange());
[$startCell, $endCell] = $mergeRange[0];
$start = Coordinate::coordinateFromString($startCell);
$end = Coordinate::coordinateFromString($endCell);
Expand Down
1 change: 1 addition & 0 deletions src/PhpSpreadsheet/Writer/Ods/Formula.php
Expand Up @@ -7,6 +7,7 @@

class Formula
{
/** @var array */
private $definedNames = [];

/**
Expand Down