Skip to content

Commit 07339c6

Browse files
author
Mark Baker
authored
Merge branch 'master' into Issue-2551-Prepare-Excel-Functions-as-Array-Functions
2 parents 435bbd5 + 0ff0187 commit 07339c6

File tree

23 files changed

+1024
-83
lines changed

23 files changed

+1024
-83
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2929
- Full support of the above CF Rules for the Xlsx Reader and Writer; even when the file being loaded has CF rules listed in the `<extLst><ext><ConditionalFormattings>` element for the worksheet rather than the `<ConditionalFormatting>` element.
3030
- Provision of a CellMatcher to identify if rules are matched for a cell, and which matching style will be applied.
3131
- Improved documentation and examples, covering all supported CF rule types.
32+
- Add support for one digit decimals (FORMAT_NUMBER_0, FORMAT_PERCENTAGE_0). [PR #2525](https://github.com/PHPOffice/PhpSpreadsheet/pull/2525)
3233

3334
### Changed
3435

35-
- Additional Russian translations for Excel Functions (courtesy of aleks-samurai)
36+
- Additional Russian translations for Excel Functions (courtesy of aleks-samurai).
37+
- Improved code coverage for NumberFormat. [PR #2556](https://github.com/PHPOffice/PhpSpreadsheet/pull/2556)
3638

3739
### Deprecated
3840

@@ -63,6 +65,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
6365
[PR #2489](https://github.com/PHPOffice/PhpSpreadsheet/pull/2489)
6466
- Xlsx Reader fix height and width for oneCellAnchorDrawings.
6567
[PR #2492](https://github.com/PHPOffice/PhpSpreadsheet/pull/2492)
68+
- Fix rounding error in NumberFormat::NUMBER_PERCENTAGE, NumberFormat::NUMBER_PERCENTAGE_00. [PR #2555](https://github.com/PHPOffice/PhpSpreadsheet/pull/2555)
69+
6670

6771
## 1.21.0 - 2022-01-06
6872

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/topics/reading-and-writing-to-file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Pdf')
860860
Or you can instantiate directly the writer of your choice like so:
861861

862862
```php
863-
$writer = \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf($spreadsheet);
863+
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf($spreadsheet);
864864
```
865865

866866
#### Custom implementation or configuration

phpstan-baseline.neon

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ parameters:
6666
path: src/PhpSpreadsheet/Calculation/Calculation.php
6767

6868
-
69-
message: "#^Cannot access offset int on mixed\\.$#"
69+
message: "#^Cannot access offset int(<0, max>)? on mixed\\.$#"
7070
count: 16
7171
path: src/PhpSpreadsheet/Calculation/Calculation.php
7272

@@ -1461,7 +1461,7 @@ parameters:
14611461
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
14621462

14631463
-
1464-
message: "#^Parameter \\#1 \\$array_arg of function uasort expects array, mixed given\\.$#"
1464+
message: "#^Parameter \\#1 \\$array_arg of function uasort expects array(<T>)?, mixed given\\.$#"
14651465
count: 1
14661466
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
14671467

@@ -1471,7 +1471,7 @@ parameters:
14711471
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
14721472

14731473
-
1474-
message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\(mixed, mixed\\)\\: int, array\\{'self', 'vlookupSort'\\} given\\.$#"
1474+
message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\((mixed|T), (mixed|T)\\)\\: int, array\\{'self', 'vlookupSort'\\} given\\.$#"
14751475
count: 1
14761476
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
14771477

@@ -5205,11 +5205,6 @@ parameters:
52055205
count: 1
52065206
path: src/PhpSpreadsheet/Shared/StringHelper.php
52075207

5208-
-
5209-
message: "#^Static property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:\\$isIconvEnabled \\(bool\\) in isset\\(\\) is not nullable\\.$#"
5210-
count: 1
5211-
path: src/PhpSpreadsheet/Shared/StringHelper.php
5212-
52135208
-
52145209
message: "#^Static property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:\\$thousandsSeparator \\(string\\) in isset\\(\\) is not nullable\\.$#"
52155210
count: 1
@@ -5365,11 +5360,6 @@ parameters:
53655360
count: 1
53665361
path: src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php
53675362

5368-
-
5369-
message: "#^Array \\(array\\<PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\>\\) does not accept object\\.$#"
5370-
count: 1
5371-
path: src/PhpSpreadsheet/Shared/Trend/Trend.php
5372-
53735363
-
53745364
message: "#^Call to an undefined method object\\:\\:getGoodnessOfFit\\(\\)\\.$#"
53755365
count: 1
@@ -5705,16 +5695,6 @@ parameters:
57055695
count: 1
57065696
path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php
57075697

5708-
-
5709-
message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(\\)\\: mixed, array\\{'self', 'escapeQuotesCallback'\\} given\\.$#"
5710-
count: 1
5711-
path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php
5712-
5713-
-
5714-
message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(\\)\\: mixed, array\\{'self', 'setLowercaseCallback'\\} given\\.$#"
5715-
count: 1
5716-
path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php
5717-
57185698
-
57195699
message: "#^Parameter \\#2 \\$replace of function str_replace expects array\\|string, int given\\.$#"
57205700
count: 1
@@ -5730,11 +5710,6 @@ parameters:
57305710
count: 1
57315711
path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php
57325712

5733-
-
5734-
message: "#^Parameter \\#3 \\$subject of function preg_replace_callback expects array\\|string, string\\|null given\\.$#"
5735-
count: 1
5736-
path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php
5737-
57385713
-
57395714
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\NumberFormat\\\\Formatter\\:\\:splitFormat\\(\\) has no return type specified\\.$#"
57405715
count: 1
@@ -5890,11 +5865,6 @@ parameters:
58905865
count: 1
58915866
path: src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php
58925867

5893-
-
5894-
message: "#^Array \\(array\\<PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter\\\\Column\\\\Rule\\>\\) does not accept mixed\\.$#"
5895-
count: 1
5896-
path: src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php
5897-
58985868
-
58995869
message: "#^Cannot call method setParent\\(\\) on mixed\\.$#"
59005870
count: 1
@@ -6076,7 +6046,7 @@ parameters:
60766046
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
60776047

60786048
-
6079-
message: "#^Parameter \\#1 \\$row of method PhpOffice\\\\PhpSpreadsheet\\\\Collection\\\\Cells\\:\\:removeRow\\(\\) expects string, int given\\.$#"
6049+
message: "#^Parameter \\#1 \\$row of method PhpOffice\\\\PhpSpreadsheet\\\\Collection\\\\Cells\\:\\:removeRow\\(\\) expects string, int(<1, max>)? given\\.$#"
60806050
count: 2
60816051
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
60826052

@@ -7026,7 +6996,7 @@ parameters:
70266996
path: src/PhpSpreadsheet/Writer/Xlsx.php
70276997

70286998
-
7029-
message: "#^Cannot access offset int on mixed\\.$#"
6999+
message: "#^Cannot access offset int(<0, max>)? on mixed\\.$#"
70307000
count: 2
70317001
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
70327002

@@ -7191,7 +7161,7 @@ parameters:
71917161
path: src/PhpSpreadsheet/Writer/Xlsx/DocProps.php
71927162

71937163
-
7194-
message: "#^Parameter \\#1 \\$index of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:getChartByIndex\\(\\) expects string, int given\\.$#"
7164+
message: "#^Parameter \\#1 \\$index of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:getChartByIndex\\(\\) expects string, int(<0, max>)? given\\.$#"
71957165
count: 1
71967166
path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php
71977167

@@ -7431,7 +7401,7 @@ parameters:
74317401
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
74327402

74337403
-
7434-
message: "#^Offset int on array\\<string, non\\-empty\\-array\\<int, string\\>\\> in isset\\(\\) does not exist\\.$#"
7404+
message: "#^Offset int(<1, max>)? on array\\<string, non\\-empty\\-array\\<int, string\\>\\> in isset\\(\\) does not exist\\.$#"
74357405
count: 2
74367406
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
74377407

@@ -7466,18 +7436,8 @@ parameters:
74667436
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
74677437

74687438
-
7469-
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int given\\.$#"
7470-
count: 19
7471-
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
7472-
7473-
-
7474-
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int\\<0, max\\> given\\.$#"
7475-
count: 3
7476-
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
7477-
7478-
-
7479-
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int\\<1, max\\> given\\.$#"
7480-
count: 7
7439+
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, (int|int\\<(0|1), max\\>) given\\.$#"
7440+
count: 27
74817441
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
74827442

74837443
-

phpstan-conditional.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
];
4343
// Erroneous analysis by Phpstan before PHP8 - mb_strlen does not return false
4444
$config['parameters']['ignoreErrors'][] = [
45-
'message' => '#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:countCharacters\\(\\) should return int but returns int\\|false\\.$#',
45+
'message' => '#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:countCharacters\\(\\) should return int but returns int(<0, max>)?\\|false\\.$#',
4646
'path' => __DIR__ . '/src/PhpSpreadsheet/Shared/StringHelper.php',
4747
'count' => 1,
4848
];

src/PhpSpreadsheet/Calculation/Financial/Coupons.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static function COUPDAYS(
134134
case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL:
135135
// Actual/actual
136136
if ($frequency == FinancialConstants::FREQUENCY_ANNUAL) {
137-
$daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis);
137+
$daysPerYear = (int) Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis);
138138

139139
return $daysPerYear / $frequency;
140140
}

src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class MatrixFunctions
1313
{
1414
/**
15-
* Convert parameter to matrix.
15+
* Convert parameter to Matrix.
1616
*
1717
* @param mixed $matrixValues A matrix of values
1818
*/
@@ -73,13 +73,13 @@ public static function sequence($rows = 1, $columns = 1, $start = 1, $step = 1)
7373
if ($step === 0) {
7474
return array_chunk(
7575
array_fill(0, $rows * $columns, $start),
76-
$columns
76+
max($columns, 1)
7777
);
7878
}
7979

8080
return array_chunk(
8181
range($start, $start + (($rows * $columns - 1) * $step), $step),
82-
$columns
82+
max($columns, 1)
8383
);
8484
}
8585

src/PhpSpreadsheet/Calculation/MathTrig/Random.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function () use ($min, $max, $wholeNumber) {
8282
},
8383
array_fill(0, $rows * $columns, $min)
8484
),
85-
$columns
85+
max($columns, 1)
8686
);
8787
}
8888
}

src/PhpSpreadsheet/Calculation/Statistical/Averages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function averageDeviations(...$args)
2424
$aArgs = Functions::flattenArrayIndexed($args);
2525

2626
// Return value
27-
$returnValue = 0;
27+
$returnValue = 0.0;
2828

2929
$aMean = self::average(...$args);
3030
if ($aMean === Functions::DIV0()) {

src/PhpSpreadsheet/Reader/Xls.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7912,4 +7912,17 @@ private function parseRichText($is)
79127912

79137913
return $value;
79147914
}
7915+
7916+
/**
7917+
* Phpstan 1.4.4 complains that this property is never read.
7918+
* So, we might be able to get rid of it altogether.
7919+
* For now, however, this function makes it readable,
7920+
* which satisfies Phpstan.
7921+
*
7922+
* @codeCoverageIgnore
7923+
*/
7924+
public function getMapCellStyleXfIndex(): array
7925+
{
7926+
return $this->mapCellStyleXfIndex;
7927+
}
79157928
}

src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ private function hqr2(): void
415415
$norm = 0.0;
416416

417417
for ($i = 0; $i < $nn; ++$i) {
418-
if (($i < $low) || ($i > $high)) {
418+
if ($i > $high) {
419419
$this->d[$i] = $this->H[$i][$i];
420420
$this->e[$i] = 0.0;
421421
}
@@ -762,7 +762,7 @@ private function hqr2(): void
762762

763763
// Vectors of isolated roots
764764
for ($i = 0; $i < $nn; ++$i) {
765-
if ($i < $low | $i > $high) {
765+
if ($i > $high) {
766766
for ($j = $i; $j < $nn; ++$j) {
767767
$this->V[$i][$j] = $this->H[$i][$j];
768768
}

src/PhpSpreadsheet/Shared/OLE/PPS/Root.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ public function save($fileHandle)
7171
$this->fileHandle = $fileHandle;
7272

7373
// Initial Setting for saving
74-
$this->bigBlockSize = 2 ** (
74+
$this->bigBlockSize = (int) (2 ** (
7575
(isset($this->bigBlockSize)) ? self::adjust2($this->bigBlockSize) : 9
76-
);
77-
$this->smallBlockSize = 2 ** (
76+
));
77+
$this->smallBlockSize = (int) (2 ** (
7878
(isset($this->smallBlockSize)) ? self::adjust2($this->smallBlockSize) : 6
79-
);
79+
));
8080

8181
// Make an array of PPS's (for Save)
8282
$aList = [];

src/PhpSpreadsheet/Shared/StringHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class StringHelper
4949
/**
5050
* Is iconv extension avalable?
5151
*
52-
* @var bool
52+
* @var ?bool
5353
*/
5454
private static $isIconvEnabled;
5555

src/PhpSpreadsheet/Shared/Trend/Trend.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public static function calculate($trendType = self::TREND_BEST_FIT, $yValues = [
7272
case self::TREND_POWER:
7373
if (!isset(self::$trendCache[$key])) {
7474
$className = '\PhpOffice\PhpSpreadsheet\Shared\Trend\\' . $trendType . 'BestFit';
75+
// @phpstan-ignore-next-line
7576
self::$trendCache[$key] = new $className($yValues, $xValues, $const);
7677
}
7778

src/PhpSpreadsheet/Spreadsheet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function getRibbonXMLData($what = 'all') //we need some constants here...
313313
break;
314314
case 'target':
315315
case 'data':
316-
if (is_array($this->ribbonXMLData) && isset($this->ribbonXMLData[$what])) {
316+
if (is_array($this->ribbonXMLData)) {
317317
$returnData = $this->ribbonXMLData[$what];
318318
}
319319

src/PhpSpreadsheet/Style/NumberFormat.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ class NumberFormat extends Supervisor
1010
const FORMAT_TEXT = '@';
1111

1212
const FORMAT_NUMBER = '0';
13+
const FORMAT_NUMBER_0 = '0.0';
1314
const FORMAT_NUMBER_00 = '0.00';
1415
const FORMAT_NUMBER_COMMA_SEPARATED1 = '#,##0.00';
1516
const FORMAT_NUMBER_COMMA_SEPARATED2 = '#,##0.00_-';
1617

1718
const FORMAT_PERCENTAGE = '0%';
19+
const FORMAT_PERCENTAGE_0 = '0.0%';
1820
const FORMAT_PERCENTAGE_00 = '0.00%';
1921

2022
const FORMAT_DATE_YYYYMMDD2 = 'yyyy-mm-dd';

0 commit comments

Comments
 (0)