From 91af5bbc4f99dd17a999220f5ca8d03d74eb41e0 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 20 May 2021 22:45:16 +0200 Subject: [PATCH] Resolve phpcs issues --- src/PhpSpreadsheet/Cell/AddressHelper.php | 48 ++++++++++---------- tests/PhpSpreadsheetTests/Style/FontTest.php | 23 ++++++++++ 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/PhpSpreadsheet/Cell/AddressHelper.php b/src/PhpSpreadsheet/Cell/AddressHelper.php index 81eea788..499d248c 100644 --- a/src/PhpSpreadsheet/Cell/AddressHelper.php +++ b/src/PhpSpreadsheet/Cell/AddressHelper.php @@ -74,35 +74,33 @@ class AddressHelper int $currentColumnNumber = 1 ): string { if (substr($formula, 0, 3) == 'of:') { - // We have a SpreasheetML Formula + // We have an old-style SpreadsheetML Formula return self::convertSpreadsheetMLFormula($formula); - } else { - // Convert R1C1 style references to A1 style references (but only when not quoted) - $temp = explode('"', $formula); - $key = false; - foreach ($temp as &$value) { - // Only replace in alternate array entries (i.e. non-quoted blocks) - if ($key = !$key) { - preg_match_all(self::R1C1_COORDINATE_REGEX, $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); - // Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way - // through the formula from left to right. Reversing means that we work right to left.through - // the formula - $cellReferences = array_reverse($cellReferences); - // Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent, - // then modify the formula to use that new reference - foreach ($cellReferences as $cellReference) { - $A1CellReference = self::convertToA1($cellReference[0][0], $currentRowNumber, $currentColumnNumber); - $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0])); - } - } - } - unset($value); } - // Then rebuild the formula string - $formula = implode('"', $temp); + // Convert R1C1 style references to A1 style references (but only when not quoted) + $temp = explode('"', $formula); + $key = false; + foreach ($temp as &$value) { + // Only replace in alternate array entries (i.e. non-quoted blocks) + if ($key = !$key) { + preg_match_all(self::R1C1_COORDINATE_REGEX, $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); + // Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way + // through the formula from left to right. Reversing means that we work right to left.through + // the formula + $cellReferences = array_reverse($cellReferences); + // Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent, + // then modify the formula to use that new reference + foreach ($cellReferences as $cellReference) { + $A1CellReference = self::convertToA1($cellReference[0][0], $currentRowNumber, $currentColumnNumber); + $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0])); + } + } + } + unset($value); - return $formula; + // Then rebuild the formula string + return implode('"', $temp); } /** diff --git a/tests/PhpSpreadsheetTests/Style/FontTest.php b/tests/PhpSpreadsheetTests/Style/FontTest.php index c014a4b6..9504e33e 100644 --- a/tests/PhpSpreadsheetTests/Style/FontTest.php +++ b/tests/PhpSpreadsheetTests/Style/FontTest.php @@ -7,6 +7,29 @@ use PHPUnit\Framework\TestCase; class FontTest extends TestCase { + public function testSize(): void + { + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + $cell = $sheet->getCell('A1'); + $cell->setValue('Cell A1'); + $font = $cell->getStyle()->getFont(); + + $font->setSize(15); + self::assertSame(15, $font->getSize(), 'Set to 15'); + + $font->setSize(''); + self::assertSame(10, $font->getSize(), 'Should be the default 10'); + + $font->setSize(14); + $font->setSize(0); + self::assertSame(10, $font->getSize(), 'Should be the default 10'); + + $font->setSize(13); + $font->setSize(-1); + self::assertSame(13, $font->getSize(), 'Should still be 13'); + } + public function testSuperSubScript(): void { $spreadsheet = new Spreadsheet();