From 64a197ee42aa1067cc50be2acb429f2a595bebe9 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 10 Nov 2022 09:45:01 +0100 Subject: [PATCH] Styling fixes --- src/PhpSpreadsheet/Shared/StringHelper.php | 3 +- .../Shared/StringHelperTest.php | 176 +++++++++--------- 2 files changed, 89 insertions(+), 90 deletions(-) diff --git a/src/PhpSpreadsheet/Shared/StringHelper.php b/src/PhpSpreadsheet/Shared/StringHelper.php index a426b077b..ab124907b 100644 --- a/src/PhpSpreadsheet/Shared/StringHelper.php +++ b/src/PhpSpreadsheet/Shared/StringHelper.php @@ -572,9 +572,8 @@ class StringHelper { $match = []; if (preg_match(self::STRING_REGEXP_PERCENT, $operand, $match, PREG_UNMATCHED_AS_NULL)) { - //Calculate the percentage - $operand = (float)((($match['PrefixedSign'] ?? $match['PrefixedSign2'] ?? $match['PostfixedSign']) ?? '') . ($match['PostfixedValue'] ?? $match['PrefixedValue'])) / 100; + $operand = (float) ((($match['PrefixedSign'] ?? $match['PrefixedSign2'] ?? $match['PostfixedSign']) ?? '') . ($match['PostfixedValue'] ?? $match['PrefixedValue'])) / 100; return true; } diff --git a/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php b/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php index b534782cf..34bde2882 100644 --- a/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php +++ b/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php @@ -186,94 +186,94 @@ class StringHelperTest extends TestCase 'negative leading percent' => ['-0.02', '-%2'], //Percent position permutations - 'permutation_1' => ['0.02', '2%'], - 'permutation_2' => ['0.02', ' 2%'], - 'permutation_3' => ['0.02', '2% '], - 'permutation_4' => ['0.02', ' 2 % '], - 'permutation_5' => ['0.0275', '2.75% '], - 'permutation_6' => ['0.0275', ' 2.75% '], - 'permutation_7' => ['0.0275', ' 2.75 % '], - 'permutation_8' => [' 2 . 75 %', ' 2 . 75 %'], - 'permutation_9' => [' 2.7 5 % ', ' 2.7 5 % '], - 'permutation_10' => ['-0.02', '-2%'], - 'permutation_11' => ['-0.02', ' -2% '], - 'permutation_12' => ['-0.02', '- 2% '], - 'permutation_13' => ['-0.02', '-2 % '], - 'permutation_14' => ['-0.0275', '-2.75% '], - 'permutation_15' => ['-0.0275', ' -2.75% '], - 'permutation_16' => ['-0.0275', '-2.75 % '], - 'permutation_17' => ['-0.0275', ' - 2.75 % '], - 'permutation_18' => ['0.02', '2%'], - 'permutation_19' => ['0.02', '% 2 '], - 'permutation_20' => ['0.02', ' %2 '], - 'permutation_21' => ['0.02', ' % 2 '], - 'permutation_22' => ['0.0275', '%2.75 '], - 'permutation_23' => ['0.0275', ' %2.75 '], - 'permutation_24' => ['0.0275', ' % 2.75 '], - 'permutation_25' => [' %2 . 75 ', ' %2 . 75 '], - 'permutation_26' => [' %2.7 5 ', ' %2.7 5 '], - 'permutation_27' => [' % 2 . 75 ', ' % 2 . 75 '], - 'permutation_28' => [' % 2.7 5 ', ' % 2.7 5 '], - 'permutation_29' => ['-0.0275', '-%2.75 '], - 'permutation_30' => ['-0.0275', ' - %2.75 '], - 'permutation_31' => ['-0.0275', '- % 2.75 '], - 'permutation_32' => ['-0.0275', ' - % 2.75 '], - 'permutation_33' => ['0.02', '2%'], - 'permutation_34' => ['0.02', '2 %'], - 'permutation_35' => ['0.02', ' 2%'], - 'permutation_36' => ['0.02', ' 2 % '], - 'permutation_37' => ['0.0275', '2.75%'], - 'permutation_38' => ['0.0275', ' 2.75 % '], - 'permutation_39' => ['2 . 75 % ', '2 . 75 % '], - 'permutation_40' => ['-0.0275', '-2.75% '], - 'permutation_41' => ['-0.0275', '- 2.75% '], - 'permutation_42' => ['-0.0275', ' - 2.75% '], - 'permutation_43' => ['-0.0275', ' -2.75 % '], - 'permutation_44' => ['-2. 75 % ', '-2. 75 % '], - 'permutation_45' => ['%', '%'], - 'permutation_46' => ['0.02', '%2 '], - 'permutation_47' => ['0.02', '% 2 '], - 'permutation_48' => ['0.02', ' %2 '], - 'permutation_49' => ['0.02', '% 2 '], - 'permutation_50' => ['0.02', ' % 2 '], - 'permutation_51' => ['0.02', ' 2 % '], - 'permutation_52' => ['-0.02', '-2%'], - 'permutation_53' => ['-0.02', '- %2'], - 'permutation_54' => ['-0.02', ' -%2 '], - 'permutation_55' => ['2%2', '2%2'], - 'permutation_56' => [' 2% %', ' 2% %'], - 'permutation_57' => [' % 2 -', ' % 2 -'], - 'permutation_58' => ['-0.02', '%-2'], - 'permutation_59' => ['-0.02', ' % - 2'], - 'permutation_60' => ['-0.0275', '%-2.75 '], - 'permutation_61' => ['-0.0275', ' % - 2.75 '], - 'permutation_62' => ['-0.0275', ' % - 2.75 '], - 'permutation_63' => ['-0.0275', ' % - 2.75 '], - 'permutation_64' => ['0.0275', ' % + 2.75 '], - 'permutation_65' => ['0.0275', ' % + 2.75 '], - 'permutation_66' => ['0.0275', ' % + 2.75 '], - 'permutation_67' => ['0.02', '+2%'], - 'permutation_68' => ['0.02', ' +2% '], - 'permutation_69' => ['0.02', '+ 2% '], - 'permutation_70' => ['0.02', '+2 % '], - 'permutation_71' => ['0.0275', '+2.75% '], - 'permutation_72' => ['0.0275', ' +2.75% '], - 'permutation_73' => ['0.0275', '+2.75 % '], - 'permutation_74' => ['0.0275', ' + 2.75 % '], - 'permutation_75' => ['-2.5E-6', '-2.5E-4%'], - 'permutation_76' => ['200', '2E4%'], - 'permutation_77' => ['-2.5E-8', '-%2.50E-06'], - 'permutation_78' => [' - % 2.50 E -06 ', ' - % 2.50 E -06 '], - 'permutation_79' => ['-2.5E-8', ' - % 2.50E-06 '], - 'permutation_80' => [' - % 2.50E- 06 ', ' - % 2.50E- 06 '], - 'permutation_81' => [' - % 2.50E - 06 ', ' - % 2.50E - 06 '], - 'permutation_82' => ['-2.5E-6', '-2.5e-4%'], - 'permutation_83' => ['200', '2e4%'], - 'permutation_84' => ['-2.5E-8', '-%2.50e-06'], - 'permutation_85' => [' - % 2.50 e -06 ', ' - % 2.50 e -06 '], - 'permutation_86' => ['-2.5E-8', ' - % 2.50e-06 '], - 'permutation_87' => [' - % 2.50e- 06 ', ' - % 2.50e- 06 '], - 'permutation_88' => [' - % 2.50e - 06 ', ' - % 2.50e - 06 '], + 'permutation_1' => ['0.02', '2%'], + 'permutation_2' => ['0.02', ' 2%'], + 'permutation_3' => ['0.02', '2% '], + 'permutation_4' => ['0.02', ' 2 % '], + 'permutation_5' => ['0.0275', '2.75% '], + 'permutation_6' => ['0.0275', ' 2.75% '], + 'permutation_7' => ['0.0275', ' 2.75 % '], + 'permutation_8' => [' 2 . 75 %', ' 2 . 75 %'], + 'permutation_9' => [' 2.7 5 % ', ' 2.7 5 % '], + 'permutation_10' => ['-0.02', '-2%'], + 'permutation_11' => ['-0.02', ' -2% '], + 'permutation_12' => ['-0.02', '- 2% '], + 'permutation_13' => ['-0.02', '-2 % '], + 'permutation_14' => ['-0.0275', '-2.75% '], + 'permutation_15' => ['-0.0275', ' -2.75% '], + 'permutation_16' => ['-0.0275', '-2.75 % '], + 'permutation_17' => ['-0.0275', ' - 2.75 % '], + 'permutation_18' => ['0.02', '2%'], + 'permutation_19' => ['0.02', '% 2 '], + 'permutation_20' => ['0.02', ' %2 '], + 'permutation_21' => ['0.02', ' % 2 '], + 'permutation_22' => ['0.0275', '%2.75 '], + 'permutation_23' => ['0.0275', ' %2.75 '], + 'permutation_24' => ['0.0275', ' % 2.75 '], + 'permutation_25' => [' %2 . 75 ', ' %2 . 75 '], + 'permutation_26' => [' %2.7 5 ', ' %2.7 5 '], + 'permutation_27' => [' % 2 . 75 ', ' % 2 . 75 '], + 'permutation_28' => [' % 2.7 5 ', ' % 2.7 5 '], + 'permutation_29' => ['-0.0275', '-%2.75 '], + 'permutation_30' => ['-0.0275', ' - %2.75 '], + 'permutation_31' => ['-0.0275', '- % 2.75 '], + 'permutation_32' => ['-0.0275', ' - % 2.75 '], + 'permutation_33' => ['0.02', '2%'], + 'permutation_34' => ['0.02', '2 %'], + 'permutation_35' => ['0.02', ' 2%'], + 'permutation_36' => ['0.02', ' 2 % '], + 'permutation_37' => ['0.0275', '2.75%'], + 'permutation_38' => ['0.0275', ' 2.75 % '], + 'permutation_39' => ['2 . 75 % ', '2 . 75 % '], + 'permutation_40' => ['-0.0275', '-2.75% '], + 'permutation_41' => ['-0.0275', '- 2.75% '], + 'permutation_42' => ['-0.0275', ' - 2.75% '], + 'permutation_43' => ['-0.0275', ' -2.75 % '], + 'permutation_44' => ['-2. 75 % ', '-2. 75 % '], + 'permutation_45' => ['%', '%'], + 'permutation_46' => ['0.02', '%2 '], + 'permutation_47' => ['0.02', '% 2 '], + 'permutation_48' => ['0.02', ' %2 '], + 'permutation_49' => ['0.02', '% 2 '], + 'permutation_50' => ['0.02', ' % 2 '], + 'permutation_51' => ['0.02', ' 2 % '], + 'permutation_52' => ['-0.02', '-2%'], + 'permutation_53' => ['-0.02', '- %2'], + 'permutation_54' => ['-0.02', ' -%2 '], + 'permutation_55' => ['2%2', '2%2'], + 'permutation_56' => [' 2% %', ' 2% %'], + 'permutation_57' => [' % 2 -', ' % 2 -'], + 'permutation_58' => ['-0.02', '%-2'], + 'permutation_59' => ['-0.02', ' % - 2'], + 'permutation_60' => ['-0.0275', '%-2.75 '], + 'permutation_61' => ['-0.0275', ' % - 2.75 '], + 'permutation_62' => ['-0.0275', ' % - 2.75 '], + 'permutation_63' => ['-0.0275', ' % - 2.75 '], + 'permutation_64' => ['0.0275', ' % + 2.75 '], + 'permutation_65' => ['0.0275', ' % + 2.75 '], + 'permutation_66' => ['0.0275', ' % + 2.75 '], + 'permutation_67' => ['0.02', '+2%'], + 'permutation_68' => ['0.02', ' +2% '], + 'permutation_69' => ['0.02', '+ 2% '], + 'permutation_70' => ['0.02', '+2 % '], + 'permutation_71' => ['0.0275', '+2.75% '], + 'permutation_72' => ['0.0275', ' +2.75% '], + 'permutation_73' => ['0.0275', '+2.75 % '], + 'permutation_74' => ['0.0275', ' + 2.75 % '], + 'permutation_75' => ['-2.5E-6', '-2.5E-4%'], + 'permutation_76' => ['200', '2E4%'], + 'permutation_77' => ['-2.5E-8', '-%2.50E-06'], + 'permutation_78' => [' - % 2.50 E -06 ', ' - % 2.50 E -06 '], + 'permutation_79' => ['-2.5E-8', ' - % 2.50E-06 '], + 'permutation_80' => [' - % 2.50E- 06 ', ' - % 2.50E- 06 '], + 'permutation_81' => [' - % 2.50E - 06 ', ' - % 2.50E - 06 '], + 'permutation_82' => ['-2.5E-6', '-2.5e-4%'], + 'permutation_83' => ['200', '2e4%'], + 'permutation_84' => ['-2.5E-8', '-%2.50e-06'], + 'permutation_85' => [' - % 2.50 e -06 ', ' - % 2.50 e -06 '], + 'permutation_86' => ['-2.5E-8', ' - % 2.50e-06 '], + 'permutation_87' => [' - % 2.50e- 06 ', ' - % 2.50e- 06 '], + 'permutation_88' => [' - % 2.50e - 06 ', ' - % 2.50e - 06 '], ]; } }