From b4fc92ec7ed8443167dc506e4f2f6148fe93f852 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Tue, 3 May 2022 12:13:10 +0200 Subject: [PATCH 1/2] Simplify validation of columnId/rowId values when creating a CellAddress object --- src/PhpSpreadsheet/Cell/CellAddress.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/PhpSpreadsheet/Cell/CellAddress.php b/src/PhpSpreadsheet/Cell/CellAddress.php index d587dcd1..069c9ac9 100644 --- a/src/PhpSpreadsheet/Cell/CellAddress.php +++ b/src/PhpSpreadsheet/Cell/CellAddress.php @@ -47,15 +47,9 @@ class CellAddress */ private static function validateColumnAndRow($columnId, $rowId): void { - $array = [$columnId, $rowId]; - array_walk( - $array, - function ($value): void { - if (!is_numeric($value) || $value <= 0) { - throw new Exception('Row and Column Ids must be positive integer values'); - } - } - ); + if (!is_numeric($columnId) || $columnId <= 0 || !is_numeric($rowId) || $rowId <= 0) { + throw new Exception('Row and Column Ids must be positive integer values'); + } } /** From e043cf3e243a508a3c777b138c02a212a18ce423 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Tue, 3 May 2022 13:22:43 +0200 Subject: [PATCH 2/2] Eliminate loop in `trimSheetFromCellReference()` method --- src/PhpSpreadsheet/Calculation/Functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpSpreadsheet/Calculation/Functions.php b/src/PhpSpreadsheet/Calculation/Functions.php index dc6ee82e..8075811f 100644 --- a/src/PhpSpreadsheet/Calculation/Functions.php +++ b/src/PhpSpreadsheet/Calculation/Functions.php @@ -705,8 +705,8 @@ class Functions public static function trimSheetFromCellReference(string $coordinate): string { - while (strpos($coordinate, '!') !== false) { - $coordinate = substr($coordinate, strpos($coordinate, '!') + 1); + if (strpos($coordinate, '!') !== false) { + $coordinate = substr($coordinate, strrpos($coordinate, '!') + 1); } return $coordinate;