Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/PhpSpreadsheet/Shared/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,4 +722,19 @@ public static function convertPostToString(string $index, string $default = ''):

return $default;
}

/**
* Php introduced str_increment with Php8.3,
* but didn't issue deprecation notices till 8.5.
*
* @codeCoverageIgnore
*/
public static function stringIncrement(string &$str): void
{
if (function_exists('str_increment')) {
$str = str_increment($str); // @phpstan-ignore-line
} else {
++$str; // @phpstan-ignore-line
}
}
}
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Writer/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ public function generateSheetData(): string
}
++$column;
/** @var string $colStr */
++$colStr;
StringHelper::stringIncrement($colStr);
}
$html .= $this->generateRow($sheet, $rowData, $row - 1, $cellType);
}
Expand Down Expand Up @@ -941,7 +941,7 @@ private function buildCssPerSheet(Worksheet $sheet, array &$css): void
if ($this->shouldGenerateColumn($sheet, $colStr)) {
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = self::DEFAULT_CELL_WIDTH_POINTS . 'pt';
}
++$colStr;
StringHelper::stringIncrement($colStr);
}

// col elements, loop through columnDimensions and set width
Expand Down
28 changes: 28 additions & 0 deletions src/PhpSpreadsheet/Writer/Pdf/Dompdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public function save($filename, int $flags = 0): void
$orientation = ($orientation == 'L') ? 'landscape' : 'portrait';

// Create PDF
$restoreHandler = false;
if (PHP_VERSION_ID >= self::$temporaryVersionCheck) {
// @codeCoverageIgnoreStart
set_error_handler(self::specialErrorHandler(...));
$restoreHandler = true;
// @codeCoverageIgnoreEnd
}
$pdf = $this->createExternalWriterInstance();
$pdf->setPaper($paperSize, $orientation);

Expand All @@ -53,6 +60,27 @@ public function save($filename, int $flags = 0): void
// Write to file
fwrite($fileHandle, $pdf->output() ?? '');

if ($restoreHandler) {
restore_error_handler(); // @codeCoverageIgnore
}
parent::restoreStateAfterSave();
}

protected static int $temporaryVersionCheck = 80500;

/**
* Temporary handler for Php8.5 waiting for Dompdf release.
*
* @codeCoverageIgnore
*/
public function specialErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool
{
if ($errno === E_DEPRECATED) {
if (preg_match('/canonical|imagedestroy/', $errstr) === 1) {
return true;
}
}

return false; // continue error handling
}
}
18 changes: 18 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

function phpunit10ErrorHandler(int $errno, string $errstr, string $filename, int $lineno): bool
{
if (strIncrement85(PHP_VERSION_ID, $errno, $errstr, $filename)) {
return true; // message suppressed - stop error handling
}
$x = error_reporting() & $errno;
if (
in_array(
Expand All @@ -31,6 +34,21 @@ function phpunit10ErrorHandler(int $errno, string $errstr, string $filename, int
return false; // continue error handling
}

function strIncrement85(int $version, int $errno, string $errstr, string $filename): bool
{
if ($version < 80500 || $errno !== E_DEPRECATED) {
return false;
}
if (preg_match('/Increment on non-numeric string/', $errstr) === 1) {
return true;
}
if (preg_match('/canonical/', $errstr) === 1 && preg_match('/mitoteam/', $filename) === 1) {
return true;
}

return false;
}

if (!method_exists(PHPUnit\Framework\TestCase::class, 'setOutputCallback')) {
set_error_handler('phpunit10ErrorHandler');
}