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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). Thia is a
- Unexpected Exception in Php DateTime. [Issue #4696](https://github.com/PHPOffice/PhpSpreadsheet/issues/4696) [Issue #917](https://github.com/PHPOffice/PhpSpreadsheet/issues/917) [PR #4697](https://github.com/PHPOffice/PhpSpreadsheet/pull/4697)
- Add missing Dutch translation to translation file. [PR #4707](https://github.com/PHPOffice/PhpSpreadsheet/pull/4707)
- Fix lots of typos throughout codebase. [PR #4705](https://github.com/PHPOffice/PhpSpreadsheet/pull/4705)
- Apply small code style improvements. [PR #4708](https://github.com/PHPOffice/PhpSpreadsheet/pull/4708)
- Implement missing `INFO` function. [PR #4709](https://github.com/PHPOffice/PhpSpreadsheet/pull/4709)

## 2025-10-25 - 5.2.0
Expand Down
18 changes: 3 additions & 15 deletions src/PhpSpreadsheet/Calculation/FormulaParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,8 @@ private function parseToTokens(): void
$tokenCount = count($tokens1);
for ($i = 0; $i < $tokenCount; ++$i) {
$token = $tokens1[$i];
if (isset($tokens1[$i - 1])) {
$previousToken = $tokens1[$i - 1];
} else {
$previousToken = null;
}
if (isset($tokens1[$i + 1])) {
$nextToken = $tokens1[$i + 1];
} else {
$nextToken = null;
}
$previousToken = $tokens1[$i - 1] ?? null;
$nextToken = $tokens1[$i + 1] ?? null;

if ($token->getTokenType() != FormulaToken::TOKEN_TYPE_WHITESPACE) {
$tokens2[] = $token;
Expand Down Expand Up @@ -518,11 +510,7 @@ private function parseToTokens(): void
$tokenCount = count($tokens2);
for ($i = 0; $i < $tokenCount; ++$i) {
$token = $tokens2[$i];
if (isset($tokens2[$i - 1])) {
$previousToken = $tokens2[$i - 1];
} else {
$previousToken = null;
}
$previousToken = $tokens2[$i - 1] ?? null;

if ($token->getTokenType() == FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getValue() == '-') {
if ($i == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Information/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public static function asNumber($value = null)
if (is_bool($value)) {
return (int) $value;
}
if (is_string($value) && substr($value, 0, 1) === '#') {
if (is_string($value) && str_starts_with($value, '#')) {
return $value;
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/LookupRef/Indirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static function INDIRECT($cellAddress, mixed $a1fmt, Cell $cell): string|
*/
private static function extractRequiredCells(?Worksheet $worksheet, string $cellAddress): array
{
return Calculation::getInstance($worksheet !== null ? $worksheet->getParent() : null)
return Calculation::getInstance($worksheet?->getParent())
->extractCellRange($cellAddress, $worksheet, false, createCell: true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/LookupRef/Offset.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function OFFSET(?string $cellAddress = null, $rows = 0, $columns =
/** @return mixed[] */
private static function extractRequiredCells(?Worksheet $worksheet, string $cellAddress): array
{
return Calculation::getInstance($worksheet !== null ? $worksheet->getParent() : null)
return Calculation::getInstance($worksheet?->getParent())
->extractCellRange($cellAddress, $worksheet, false);
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Cell/Coordinate.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private static function validateReferenceAndGetData($reference): array

$worksheet = $matches['worksheet'];
if ($worksheet !== '') {
if (substr($worksheet, 0, 1) === "'" && substr($worksheet, -1, 1) === "'") {
if (str_starts_with($worksheet, "'") && str_ends_with($worksheet, "'")) {
$worksheet = substr($worksheet, 1, -1);
}
$data['worksheet'] = strtolower($worksheet);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Collection/Cells.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public function getHighestColumn($row = null): string
continue;
}
$column = ($coordinate % self::MAX_COLUMN_ID) ?: self::MAX_COLUMN_ID;
$maxColumn = $maxColumn > $column ? $maxColumn : $column;
$maxColumn = max($column, $maxColumn);
}

return Coordinate::stringFromColumnIndex($maxColumn);
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Reader/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
$styleArray = self::getStyleArray($attributes);

$src = $attributes['src'];
if (substr($src, 0, 5) !== 'data:') {
if (!str_starts_with($src, 'data:')) {
$src = urldecode($src);
}
$width = isset($attributes['width']) ? (float) $attributes['width'] : ($styleArray['width'] ?? null);
Expand Down Expand Up @@ -1195,13 +1195,13 @@ private static function getStyleArray(array $attributes): array
$arrayKey = trim($value[0]);
$arrayValue = trim($value[1]);
if ($arrayKey === 'width') {
if (substr($arrayValue, -2) === 'px') {
if (str_ends_with($arrayValue, 'px')) {
$arrayValue = (string) (((float) substr($arrayValue, 0, -2)));
} else {
$arrayValue = (new CssDimension($arrayValue))->toUnit(CssDimension::UOM_PIXELS);
}
} elseif ($arrayKey === 'height') {
if (substr($arrayValue, -2) === 'px') {
if (str_ends_with($arrayValue, 'px')) {
$arrayValue = substr($arrayValue, 0, -2);
} else {
$arrayValue = (new CssDimension($arrayValue))->toUnit(CssDimension::UOM_PIXELS);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Security/XmlScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private function toUtf8(string $xml): string

private function findCharSet(string $xml): string
{
if (substr($xml, 0, 4) === "\x4c\x6f\xa7\x94") {
if (str_starts_with($xml, "\x4c\x6f\xa7\x94")) {
throw new Reader\Exception('EBCDIC encoding not permitted');
}
$encoding = Reader\Csv::guessEncodingBom('', $xml);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -2430,7 +2430,7 @@ private function readBackgroundImage(
$attrs = $rel->attributes() ?? [];
$rid = (string) ($attrs['Id'] ?? '');
$target = (string) ($attrs['Target'] ?? '');
if ($rid === $id && substr($target, 0, 2) === '..') {
if ($rid === $id && str_starts_with($target, '..')) {
$target = 'xl' . substr($target, 2);
$content = $this->getFromZipArchive($this->zip, $target);
$docSheet->setBackgroundImage($content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function format($value, string $format): string
}
// Number of digits to display before the decimal
if (preg_match('/([#0,]+)\.?/u', $format, $matches)) {
$firstZero = preg_replace('/^[#,]*/', '', $matches[1]) ?? '';
$firstZero = ltrim($matches[1], '#,');
$wholePartSize = max($wholePartSize, strlen($firstZero));
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3411,7 +3411,7 @@ public static function extractSheetTitle(?string $range, bool $returnRange = fal
public static function unApostrophizeTitle(?string $title): string
{
$title ??= '';
if ($title[0] === "'" && substr($title, -1) === "'") {
if (str_starts_with($title, "'") && str_ends_with($title, "'")) {
$title = str_replace("''", "'", substr($title, 1, -1));
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Writer/Xls/Workbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private function parseDefinedNameValue(DefinedName $definedName): string
if (empty($worksheet)) {
if (($offset === 0) || ($definedRange[$offset - 1] !== ':')) {
// We should have a worksheet
$worksheet = $definedName->getWorksheet() ? $definedName->getWorksheet()->getTitle() : null;
$worksheet = $definedName->getWorksheet()?->getTitle();
}
} else {
$worksheet = str_replace("''", "'", trim($worksheet, "'"));
Expand Down