Phpstan Baseline < 4000 Lines Part 2 Html (#3037)

Continue to reduce the size of Phpstan Baseline by fixing problems reported for Writer/Html.
This commit is contained in:
oleibman 2022-08-30 22:34:20 -07:00 committed by GitHub
parent 9eb5e7e976
commit 4f8aa806bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 360 deletions

View File

@ -3155,316 +3155,6 @@ parameters:
count: 2 count: 2
path: src/PhpSpreadsheet/Worksheet/Worksheet.php path: src/PhpSpreadsheet/Worksheet/Worksheet.php
-
message: "#^Call to function array_key_exists\\(\\) with int and array\\{none\\: 'none', dashDot\\: '1px dashed', dashDotDot\\: '1px dotted', dashed\\: '1px dashed', dotted\\: '1px dotted', double\\: '3px double', hair\\: '1px solid', medium\\: '2px solid', \\.\\.\\.\\} will always evaluate to false\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Cannot access offset 'mime' on array\\|false\\.$#"
count: 2
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Cannot access offset 0 on array\\|false\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Cannot access offset 1 on array\\|false\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Cannot call method getSubscript\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Cannot call method getSuperscript\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:calculateSpansOmitRows\\(\\) has parameter \\$candidateSpannedRow with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:calculateSpansOmitRows\\(\\) has parameter \\$sheet with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:calculateSpansOmitRows\\(\\) has parameter \\$sheetIndex with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateHTMLFooter\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateMeta\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateMeta\\(\\) has parameter \\$desc with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateMeta\\(\\) has parameter \\$val with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellCss\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellCss\\(\\) has parameter \\$cellAddress with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellCss\\(\\) has parameter \\$columnNumber with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellCss\\(\\) has parameter \\$row with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellData\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellData\\(\\) has parameter \\$cell with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellData\\(\\) has parameter \\$cellType with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellData\\(\\) has parameter \\$cssClass with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellDataValue\\(\\) has parameter \\$cell with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellDataValue\\(\\) has parameter \\$cellData with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellDataValueRich\\(\\) has parameter \\$cell with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowCellDataValueRich\\(\\) has parameter \\$cellData with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowIncludeCharts\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowIncludeCharts\\(\\) has parameter \\$coordinate with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowSpans\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowSpans\\(\\) has parameter \\$colSpan with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowSpans\\(\\) has parameter \\$html with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowSpans\\(\\) has parameter \\$rowSpan with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowWriteCell\\(\\) has parameter \\$cellData with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowWriteCell\\(\\) has parameter \\$cellType with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowWriteCell\\(\\) has parameter \\$colNum with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowWriteCell\\(\\) has parameter \\$colSpan with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowWriteCell\\(\\) has parameter \\$coordinate with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowWriteCell\\(\\) has parameter \\$cssClass with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowWriteCell\\(\\) has parameter \\$html with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowWriteCell\\(\\) has parameter \\$row with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowWriteCell\\(\\) has parameter \\$rowSpan with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateRowWriteCell\\(\\) has parameter \\$sheetIndex with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateSheetPrep\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateSheetStarts\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateSheetStarts\\(\\) has parameter \\$rowMin with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateSheetStarts\\(\\) has parameter \\$sheet with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateSheetTags\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateSheetTags\\(\\) has parameter \\$row with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateSheetTags\\(\\) has parameter \\$tbodyStart with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateSheetTags\\(\\) has parameter \\$theadEnd with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateSheetTags\\(\\) has parameter \\$theadStart with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateTableFooter\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateTableTag\\(\\) has parameter \\$html with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateTableTag\\(\\) has parameter \\$id with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateTableTag\\(\\) has parameter \\$sheetIndex with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateTableTagInline\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:generateTableTagInline\\(\\) has parameter \\$id with no type specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Parameter \\#1 \\$borderStyle of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:mapBorderStyle\\(\\) expects int, string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Parameter \\#1 \\$font of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:createCSSStyleFont\\(\\) expects PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font, PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Parameter \\#1 \\$hAlign of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:mapHAlign\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Parameter \\#1 \\$vAlign of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Html\\:\\:mapVAlign\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Parameter \\#2 \\$length of function fread expects int\\<0, max\\>, int\\<0, max\\>\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Parameter \\#3 \\$use_include_path of function fopen expects bool, int given\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/Html.php
- -
message: "#^Negated boolean expression is always false\\.$#" message: "#^Negated boolean expression is always false\\.$#"
count: 1 count: 1

View File

@ -16,7 +16,7 @@ parameters:
processTimeout: 300.0 processTimeout: 300.0
checkMissingIterableValueType: false checkMissingIterableValueType: false
ignoreErrors: ignoreErrors:
- '~^Parameter \#1 \$im(age)? of function (imagedestroy|imageistruecolor|imagealphablending|imagesavealpha|imagecolortransparent|imagecolorsforindex|imagesavealpha|imagesx|imagesy) expects (GdImage|resource), GdImage\|resource given\.$~' - '~^Parameter \#1 \$im(age)? of function (imagedestroy|imageistruecolor|imagealphablending|imagesavealpha|imagecolortransparent|imagecolorsforindex|imagesavealpha|imagesx|imagesy|imagepng) expects (GdImage|resource), GdImage\|resource given\.$~'
- '~^Parameter \#2 \$src_im(age)? of function imagecopy expects (GdImage|resource), GdImage\|resource given\.$~' - '~^Parameter \#2 \$src_im(age)? of function imagecopy expects (GdImage|resource), GdImage\|resource given\.$~'
# Accept a bit anything for assert methods # Accept a bit anything for assert methods
- '~^Parameter \#2 .* of static method PHPUnit\\Framework\\Assert\:\:assert\w+\(\) expects .*, .* given\.$~' - '~^Parameter \#2 .* of static method PHPUnit\\Framework\\Assert\:\:assert\w+\(\) expects .*, .* given\.$~'

View File

@ -287,7 +287,7 @@ class Html extends BaseWriter
/** /**
* Map border style. * Map border style.
* *
* @param int $borderStyle Sheet index * @param int|string $borderStyle Sheet index
* *
* @return string * @return string
*/ */
@ -354,7 +354,7 @@ class Html extends BaseWriter
return $this; return $this;
} }
private static function generateMeta($val, $desc) private static function generateMeta(?string $val, string $desc): string
{ {
return $val return $val
? (' <meta name="' . $desc . '" content="' . htmlspecialchars($val, Settings::htmlEntityFlags()) . '" />' . PHP_EOL) ? (' <meta name="' . $desc . '" content="' . htmlspecialchars($val, Settings::htmlEntityFlags()) . '" />' . PHP_EOL)
@ -398,7 +398,7 @@ class Html extends BaseWriter
return $html; return $html;
} }
private function generateSheetPrep() private function generateSheetPrep(): array
{ {
// Ensure that Spans have been calculated? // Ensure that Spans have been calculated?
$this->calculateSpans(); $this->calculateSpans();
@ -413,7 +413,7 @@ class Html extends BaseWriter
return $sheets; return $sheets;
} }
private function generateSheetStarts($sheet, $rowMin) private function generateSheetStarts(Worksheet $sheet, int $rowMin): array
{ {
// calculate start of <tbody>, <thead> // calculate start of <tbody>, <thead>
$tbodyStart = $rowMin; $tbodyStart = $rowMin;
@ -432,7 +432,7 @@ class Html extends BaseWriter
return [$theadStart, $theadEnd, $tbodyStart]; return [$theadStart, $theadEnd, $tbodyStart];
} }
private function generateSheetTags($row, $theadStart, $theadEnd, $tbodyStart) private function generateSheetTags(int $row, int $theadStart, int $theadEnd, int $tbodyStart): array
{ {
// <thead> ? // <thead> ?
$startTag = ($row == $theadStart) ? (' <thead>' . PHP_EOL) : ''; $startTag = ($row == $theadStart) ? (' <thead>' . PHP_EOL) : '';
@ -682,7 +682,7 @@ class Html extends BaseWriter
if ($this->embedImages || substr($imageData, 0, 6) === 'zip://') { if ($this->embedImages || substr($imageData, 0, 6) === 'zip://') {
$picture = @file_get_contents($filename); $picture = @file_get_contents($filename);
if ($picture !== false) { if ($picture !== false) {
$imageDetails = getimagesize($filename); $imageDetails = getimagesize($filename) ?: [];
// base64 encode the binary data // base64 encode the binary data
$base64 = base64_encode($picture); $base64 = base64_encode($picture);
$imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64; $imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64;
@ -697,12 +697,10 @@ class Html extends BaseWriter
$imageResource = $drawing->getImageResource(); $imageResource = $drawing->getImageResource();
if ($imageResource) { if ($imageResource) {
ob_start(); // Let's start output buffering. ob_start(); // Let's start output buffering.
// @phpstan-ignore-next-line
imagepng($imageResource); // This will normally output the image, but because of ob_start(), it won't. imagepng($imageResource); // This will normally output the image, but because of ob_start(), it won't.
$contents = ob_get_contents(); // Instead, output above is saved to $contents $contents = (string) ob_get_contents(); // Instead, output above is saved to $contents
ob_end_clean(); // End the output buffer. ob_end_clean(); // End the output buffer.
/** @phpstan-ignore-next-line */
$dataUri = 'data:image/png;base64,' . base64_encode($contents); $dataUri = 'data:image/png;base64,' . base64_encode($contents);
// Because of the nature of tables, width is more important than height. // Because of the nature of tables, width is more important than height.
@ -738,21 +736,18 @@ class Html extends BaseWriter
} }
$html .= PHP_EOL; $html .= PHP_EOL;
$imageDetails = getimagesize($chartFileName); $imageDetails = getimagesize($chartFileName) ?: [];
$filedesc = $chart->getTitle(); $filedesc = $chart->getTitle();
$filedesc = $filedesc ? $filedesc->getCaptionText() : ''; $filedesc = $filedesc ? $filedesc->getCaptionText() : '';
$filedesc = $filedesc ? htmlspecialchars($filedesc, ENT_QUOTES) : 'Embedded chart'; $filedesc = $filedesc ? htmlspecialchars($filedesc, ENT_QUOTES) : 'Embedded chart';
if ($fp = fopen($chartFileName, 'rb', 0)) { $picture = file_get_contents($chartFileName);
$picture = fread($fp, filesize($chartFileName)); if ($picture !== false) {
fclose($fp);
/** @phpstan-ignore-next-line */
$base64 = base64_encode($picture); $base64 = base64_encode($picture);
$imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64; $imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64;
$html .= '<img style="position: absolute; z-index: 1; left: ' . $chartCoordinates['xOffset'] . 'px; top: ' . $chartCoordinates['yOffset'] . 'px; width: ' . $imageDetails[0] . 'px; height: ' . $imageDetails[1] . 'px;" src="' . $imageData . '" alt="' . $filedesc . '" />' . PHP_EOL; $html .= '<img style="position: absolute; z-index: 1; left: ' . $chartCoordinates['xOffset'] . 'px; top: ' . $chartCoordinates['yOffset'] . 'px; width: ' . $imageDetails[0] . 'px; height: ' . $imageDetails[1] . 'px;" src="' . $imageData . '" alt="' . $filedesc . '" />' . PHP_EOL;
unlink($chartFileName);
} }
unlink($chartFileName);
} }
} }
} }
@ -993,8 +988,8 @@ class Html extends BaseWriter
$css = []; $css = [];
// Create CSS // Create CSS
$css['vertical-align'] = $this->mapVAlign($alignment->getVertical()); $css['vertical-align'] = $this->mapVAlign($alignment->getVertical() ?? '');
$textAlign = $this->mapHAlign($alignment->getHorizontal()); $textAlign = $this->mapHAlign($alignment->getHorizontal() ?? '');
if ($textAlign) { if ($textAlign) {
$css['text-align'] = $textAlign; $css['text-align'] = $textAlign;
if (in_array($textAlign, ['left', 'right'])) { if (in_array($textAlign, ['left', 'right'])) {
@ -1070,10 +1065,8 @@ class Html extends BaseWriter
* Create CSS style. * Create CSS style.
* *
* @param Border $border Border * @param Border $border Border
*
* @return string
*/ */
private function createCSSStyleBorder(Border $border) private function createCSSStyleBorder(Border $border): string
{ {
// Create CSS - add !important to non-none border styles for merged cells // Create CSS - add !important to non-none border styles for merged cells
$borderStyle = $this->mapBorderStyle($border->getBorderStyle()); $borderStyle = $this->mapBorderStyle($border->getBorderStyle());
@ -1095,7 +1088,8 @@ class Html extends BaseWriter
// Create CSS // Create CSS
if ($fill->getFillType() !== Fill::FILL_NONE) { if ($fill->getFillType() !== Fill::FILL_NONE) {
$value = '#' . $fill->getStartColor()->getRGB(); $value = $fill->getFillType() == Fill::FILL_NONE ?
'white' : '#' . $fill->getStartColor()->getRGB();
$css['background-color'] = $value; $css['background-color'] = $value;
} }
@ -1105,7 +1099,7 @@ class Html extends BaseWriter
/** /**
* Generate HTML footer. * Generate HTML footer.
*/ */
public function generateHTMLFooter() public function generateHTMLFooter(): string
{ {
// Construct HTML // Construct HTML
$html = ''; $html = '';
@ -1115,7 +1109,7 @@ class Html extends BaseWriter
return $html; return $html;
} }
private function generateTableTagInline(Worksheet $worksheet, $id) private function generateTableTagInline(Worksheet $worksheet, string $id): string
{ {
$style = isset($this->cssStyles['table']) ? $style = isset($this->cssStyles['table']) ?
$this->assembleCSS($this->cssStyles['table']) : ''; $this->assembleCSS($this->cssStyles['table']) : '';
@ -1135,7 +1129,7 @@ class Html extends BaseWriter
return $html; return $html;
} }
private function generateTableTag(Worksheet $worksheet, $id, &$html, $sheetIndex): void private function generateTableTag(Worksheet $worksheet, string $id, string &$html, int $sheetIndex): void
{ {
if (!$this->useInlineCss) { if (!$this->useInlineCss) {
$gridlines = $worksheet->getShowGridlines() ? ' gridlines' : ''; $gridlines = $worksheet->getShowGridlines() ? ' gridlines' : '';
@ -1188,7 +1182,7 @@ class Html extends BaseWriter
/** /**
* Generate table footer. * Generate table footer.
*/ */
private function generateTableFooter() private function generateTableFooter(): string
{ {
return ' </tbody></table>' . PHP_EOL . '</div>' . PHP_EOL; return ' </tbody></table>' . PHP_EOL . '</div>' . PHP_EOL;
} }
@ -1234,7 +1228,7 @@ class Html extends BaseWriter
return $html; return $html;
} }
private function generateRowCellCss(Worksheet $worksheet, $cellAddress, $row, $columnNumber) private function generateRowCellCss(Worksheet $worksheet, string $cellAddress, int $row, int $columnNumber): array
{ {
$cell = ($cellAddress > '') ? $worksheet->getCellCollection()->get($cellAddress) : ''; $cell = ($cellAddress > '') ? $worksheet->getCellCollection()->get($cellAddress) : '';
$coordinate = Coordinate::stringFromColumnIndex($columnNumber + 1) . ($row + 1); $coordinate = Coordinate::stringFromColumnIndex($columnNumber + 1) . ($row + 1);
@ -1260,16 +1254,17 @@ class Html extends BaseWriter
return [$cell, $cssClass, $coordinate]; return [$cell, $cssClass, $coordinate];
} }
private function generateRowCellDataValueRich($cell, &$cellData): void private function generateRowCellDataValueRich(Cell $cell, string &$cellData): void
{ {
// Loop through rich text elements // Loop through rich text elements
$elements = $cell->getValue()->getRichTextElements(); $elements = $cell->getValue()->getRichTextElements();
foreach ($elements as $element) { foreach ($elements as $element) {
// Rich text start? // Rich text start?
if ($element instanceof Run) { if ($element instanceof Run) {
$cellEnd = '';
if ($element->getFont() !== null) {
$cellData .= '<span style="' . $this->assembleCSS($this->createCSSStyleFont($element->getFont())) . '">'; $cellData .= '<span style="' . $this->assembleCSS($this->createCSSStyleFont($element->getFont())) . '">';
$cellEnd = '';
if ($element->getFont()->getSuperscript()) { if ($element->getFont()->getSuperscript()) {
$cellData .= '<sup>'; $cellData .= '<sup>';
$cellEnd = '</sup>'; $cellEnd = '</sup>';
@ -1277,6 +1272,7 @@ class Html extends BaseWriter
$cellData .= '<sub>'; $cellData .= '<sub>';
$cellEnd = '</sub>'; $cellEnd = '</sub>';
} }
}
// Convert UTF8 data to PCDATA // Convert UTF8 data to PCDATA
$cellText = $element->getText(); $cellText = $element->getText();
@ -1293,7 +1289,7 @@ class Html extends BaseWriter
} }
} }
private function generateRowCellDataValue(Worksheet $worksheet, $cell, &$cellData): void private function generateRowCellDataValue(Worksheet $worksheet, Cell $cell, ?string &$cellData): void
{ {
if ($cell->getValue() instanceof RichText) { if ($cell->getValue() instanceof RichText) {
$this->generateRowCellDataValueRich($cell, $cellData); $this->generateRowCellDataValueRich($cell, $cellData);
@ -1319,7 +1315,11 @@ class Html extends BaseWriter
} }
} }
private function generateRowCellData(Worksheet $worksheet, $cell, &$cssClass, $cellType) /**
* @param null|Cell|string $cell
* @param array|string $cssClass
*/
private function generateRowCellData(Worksheet $worksheet, $cell, &$cssClass, string $cellType): string
{ {
$cellData = '&nbsp;'; $cellData = '&nbsp;';
if ($cell instanceof Cell) { if ($cell instanceof Cell) {
@ -1339,10 +1339,10 @@ class Html extends BaseWriter
$cellData = nl2br($cellData); $cellData = nl2br($cellData);
// Extend CSS class? // Extend CSS class?
if (!$this->useInlineCss) { if (!$this->useInlineCss && is_string($cssClass)) {
$cssClass .= ' style' . $cell->getXfIndex(); $cssClass .= ' style' . $cell->getXfIndex();
$cssClass .= ' ' . $cell->getDataType(); $cssClass .= ' ' . $cell->getDataType();
} else { } elseif (is_array($cssClass)) {
if ($cellType == 'th') { if ($cellType == 'th') {
if (isset($this->cssStyles['th.style' . $cell->getXfIndex()])) { if (isset($this->cssStyles['th.style' . $cell->getXfIndex()])) {
$cssClass = array_merge($cssClass, $this->cssStyles['th.style' . $cell->getXfIndex()]); $cssClass = array_merge($cssClass, $this->cssStyles['th.style' . $cell->getXfIndex()]);
@ -1372,12 +1372,12 @@ class Html extends BaseWriter
return $cellData; return $cellData;
} }
private function generateRowIncludeCharts(Worksheet $worksheet, $coordinate) private function generateRowIncludeCharts(Worksheet $worksheet, string $coordinate): string
{ {
return $this->includeCharts ? $this->writeChartInCell($worksheet, $coordinate) : ''; return $this->includeCharts ? $this->writeChartInCell($worksheet, $coordinate) : '';
} }
private function generateRowSpans($html, $rowSpan, $colSpan) private function generateRowSpans(string $html, int $rowSpan, int $colSpan): string
{ {
$html .= ($colSpan > 1) ? (' colspan="' . $colSpan . '"') : ''; $html .= ($colSpan > 1) ? (' colspan="' . $colSpan . '"') : '';
$html .= ($rowSpan > 1) ? (' rowspan="' . $rowSpan . '"') : ''; $html .= ($rowSpan > 1) ? (' rowspan="' . $rowSpan . '"') : '';
@ -1385,7 +1385,10 @@ class Html extends BaseWriter
return $html; return $html;
} }
private function generateRowWriteCell(&$html, Worksheet $worksheet, $coordinate, $cellType, $cellData, $colSpan, $rowSpan, $cssClass, $colNum, $sheetIndex, $row): void /**
* @param array|string $cssClass
*/
private function generateRowWriteCell(string &$html, Worksheet $worksheet, string $coordinate, string $cellType, string $cellData, int $colSpan, int $rowSpan, $cssClass, int $colNum, int $sheetIndex, int $row): void
{ {
// Image? // Image?
$htmlx = $this->writeImageInCell($worksheet, $coordinate); $htmlx = $this->writeImageInCell($worksheet, $coordinate);
@ -1393,7 +1396,7 @@ class Html extends BaseWriter
$htmlx .= $this->generateRowIncludeCharts($worksheet, $coordinate); $htmlx .= $this->generateRowIncludeCharts($worksheet, $coordinate);
// Column start // Column start
$html .= ' <' . $cellType; $html .= ' <' . $cellType;
if (!$this->useInlineCss && !$this->isPdf) { if (!$this->useInlineCss && !$this->isPdf && is_string($cssClass)) {
$html .= ' class="' . $cssClass . '"'; $html .= ' class="' . $cssClass . '"';
if ($htmlx) { if ($htmlx) {
$html .= " style='position: relative;'"; $html .= " style='position: relative;'";
@ -1403,9 +1406,11 @@ class Html extends BaseWriter
// We must explicitly write the width of the <td> element because TCPDF // We must explicitly write the width of the <td> element because TCPDF
// does not recognize e.g. <col style="width:42pt"> // does not recognize e.g. <col style="width:42pt">
if ($this->useInlineCss) { if ($this->useInlineCss) {
$xcssClass = $cssClass; $xcssClass = is_array($cssClass) ? $cssClass : [];
} else { } else {
if (is_string($cssClass)) {
$html .= ' class="' . $cssClass . '"'; $html .= ' class="' . $cssClass . '"';
}
$xcssClass = []; $xcssClass = [];
} }
$width = 0; $width = 0;
@ -1416,8 +1421,7 @@ class Html extends BaseWriter
$width += $this->columnWidths[$sheetIndex][$i]; $width += $this->columnWidths[$sheetIndex][$i];
} }
} }
$xcssClass['width'] = $width . 'pt'; $xcssClass['width'] = (string) $width . 'pt';
// We must also explicitly write the height of the <td> element because TCPDF // We must also explicitly write the height of the <td> element because TCPDF
// does not recognize e.g. <tr style="height:50pt"> // does not recognize e.g. <tr style="height:50pt">
if (isset($this->cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $row]['height'])) { if (isset($this->cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $row]['height'])) {
@ -1736,7 +1740,7 @@ class Html extends BaseWriter
$this->spansAreCalculated = true; $this->spansAreCalculated = true;
} }
private function calculateSpansOmitRows($sheet, $sheetIndex, $candidateSpannedRow): void private function calculateSpansOmitRows(Worksheet $sheet, int $sheetIndex, array $candidateSpannedRow): void
{ {
// Identify which rows should be omitted in HTML. These are the rows where all the cells // Identify which rows should be omitted in HTML. These are the rows where all the cells
// participate in a merge and the where base cells are somewhere above. // participate in a merge and the where base cells are somewhere above.