Skip to content

Commit c749cb5

Browse files
authored
Merge branch 'master' into master
2 parents 8e31dba + 7b7d3bc commit c749cb5

38 files changed

+1959
-692
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ and this project adheres to [Semantic Versioning](https://semver.org).
1919
- Added Worksheet visibility in Ods Writer [PR #2850](https://github.com/PHPOffice/PhpSpreadsheet/pull/2850)
2020
- Allow Csv Reader to treat string as contents of file [Issue #1285](https://github.com/PHPOffice/PhpSpreadsheet/issues/1285) [PR #2792](https://github.com/PHPOffice/PhpSpreadsheet/pull/2792)
2121
- Allow Csv Reader to store null string rather than leave cell empty [Issue #2840](https://github.com/PHPOffice/PhpSpreadsheet/issues/2840) [PR #2842](https://github.com/PHPOffice/PhpSpreadsheet/pull/2842)
22+
- Provide new Worksheet methods to identify if a row or column is "empty", making allowance for different definitions of "empty":
23+
- Treat rows/columns containing no cell records as empty (default)
24+
- Treat cells containing a null value as empty
25+
- Treat cells containing an empty string as empty
2226

2327
### Changed
2428

29+
- Better enforcement of value modification to match specified datatype when using setValueExplicit()
30+
- Relax validation of merge cells to allow merge for a single cell reference [Issue #2776](https://github.com/PHPOffice/PhpSpreadsheet/issues/2776)
2531
- Memory and speed improvements, particularly for the Cell Collection, and the Writers.
2632

2733
See [the Discussion section on github](https://github.com/PHPOffice/PhpSpreadsheet/discussions/2821) for details of performance across versions

phpstan-baseline.neon

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,21 +1170,11 @@ parameters:
11701170
count: 2
11711171
path: src/PhpSpreadsheet/Chart/DataSeries.php
11721172

1173-
-
1174-
message: "#^Parameter \\#1 \\$angle of method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\GridLines\\:\\:setShadowAngle\\(\\) expects int, int\\|null given\\.$#"
1175-
count: 1
1176-
path: src/PhpSpreadsheet/Chart/GridLines.php
1177-
11781173
-
11791174
message: "#^Parameter \\#1 \\$color of method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\GridLines\\:\\:setGlowColor\\(\\) expects string, string\\|null given\\.$#"
11801175
count: 1
11811176
path: src/PhpSpreadsheet/Chart/GridLines.php
11821177

1183-
-
1184-
message: "#^Parameter \\#1 \\$distance of method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\GridLines\\:\\:setShadowDistance\\(\\) expects float, float\\|null given\\.$#"
1185-
count: 1
1186-
path: src/PhpSpreadsheet/Chart/GridLines.php
1187-
11881178
-
11891179
message: "#^Parameter \\#2 \\$alpha of method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\GridLines\\:\\:setGlowColor\\(\\) expects int, int\\|null given\\.$#"
11901180
count: 1
@@ -1275,36 +1265,6 @@ parameters:
12751265
count: 1
12761266
path: src/PhpSpreadsheet/Chart/Properties.php
12771267

1278-
-
1279-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Properties\\:\\:getTrueAlpha\\(\\) has no return type specified\\.$#"
1280-
count: 1
1281-
path: src/PhpSpreadsheet/Chart/Properties.php
1282-
1283-
-
1284-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Properties\\:\\:getTrueAlpha\\(\\) has parameter \\$alpha with no type specified\\.$#"
1285-
count: 1
1286-
path: src/PhpSpreadsheet/Chart/Properties.php
1287-
1288-
-
1289-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Properties\\:\\:setColorProperties\\(\\) has no return type specified\\.$#"
1290-
count: 1
1291-
path: src/PhpSpreadsheet/Chart/Properties.php
1292-
1293-
-
1294-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Properties\\:\\:setColorProperties\\(\\) has parameter \\$alpha with no type specified\\.$#"
1295-
count: 1
1296-
path: src/PhpSpreadsheet/Chart/Properties.php
1297-
1298-
-
1299-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Properties\\:\\:setColorProperties\\(\\) has parameter \\$color with no type specified\\.$#"
1300-
count: 1
1301-
path: src/PhpSpreadsheet/Chart/Properties.php
1302-
1303-
-
1304-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Properties\\:\\:setColorProperties\\(\\) has parameter \\$colorType with no type specified\\.$#"
1305-
count: 1
1306-
path: src/PhpSpreadsheet/Chart/Properties.php
1307-
13081268
-
13091269
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Renderer\\\\JpGraph\\:\\:formatDataSetLabels\\(\\) has no return type specified\\.$#"
13101270
count: 1
@@ -3155,26 +3115,6 @@ parameters:
31553115
count: 1
31563116
path: src/PhpSpreadsheet/Shared/StringHelper.php
31573117

3158-
-
3159-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:mbIsUpper\\(\\) has no return type specified\\.$#"
3160-
count: 1
3161-
path: src/PhpSpreadsheet/Shared/StringHelper.php
3162-
3163-
-
3164-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:mbIsUpper\\(\\) has parameter \\$character with no type specified\\.$#"
3165-
count: 1
3166-
path: src/PhpSpreadsheet/Shared/StringHelper.php
3167-
3168-
-
3169-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:mbStrSplit\\(\\) has no return type specified\\.$#"
3170-
count: 1
3171-
path: src/PhpSpreadsheet/Shared/StringHelper.php
3172-
3173-
-
3174-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:mbStrSplit\\(\\) has parameter \\$string with no type specified\\.$#"
3175-
count: 1
3176-
path: src/PhpSpreadsheet/Shared/StringHelper.php
3177-
31783118
-
31793119
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:sanitizeUTF8\\(\\) should return string but returns string\\|false\\.$#"
31803120
count: 1
@@ -3200,11 +3140,6 @@ parameters:
32003140
count: 1
32013141
path: src/PhpSpreadsheet/Shared/StringHelper.php
32023142

3203-
-
3204-
message: "#^Variable \\$textValue on left side of \\?\\? always exists and is not nullable\\.$#"
3205-
count: 3
3206-
path: src/PhpSpreadsheet/Shared/StringHelper.php
3207-
32083143
-
32093144
message: "#^Static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\TimeZone\\:\\:validateTimeZone\\(\\) is unused\\.$#"
32103145
count: 1
@@ -3655,11 +3590,6 @@ parameters:
36553590
count: 1
36563591
path: src/PhpSpreadsheet/Worksheet/CellIterator.php
36573592

3658-
-
3659-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Column\\:\\:\\$parent \\(PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\) does not accept PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
3660-
count: 1
3661-
path: src/PhpSpreadsheet/Worksheet/Column.php
3662-
36633593
-
36643594
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Drawing\\\\Shadow\\:\\:\\$color \\(PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Color\\) does not accept PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Color\\|null\\.$#"
36653595
count: 1
@@ -3685,11 +3615,6 @@ parameters:
36853615
count: 1
36863616
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
36873617

3688-
-
3689-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Row\\:\\:\\$worksheet \\(PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\) does not accept PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
3690-
count: 1
3691-
path: src/PhpSpreadsheet/Worksheet/Row.php
3692-
36933618
-
36943619
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\SheetView\\:\\:\\$sheetViewTypes has no type specified\\.$#"
36953620
count: 1
@@ -4477,12 +4402,12 @@ parameters:
44774402

44784403
-
44794404
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, array\\|int\\|string given\\.$#"
4480-
count: 8
4405+
count: 2
44814406
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
44824407

44834408
-
44844409
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, array\\|int\\|string\\|null given\\.$#"
4485-
count: 2
4410+
count: 1
44864411
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
44874412

44884413
-
@@ -4525,11 +4450,6 @@ parameters:
45254450
count: 2
45264451
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
45274452

4528-
-
4529-
message: "#^Part \\$xAxis\\-\\>getShadowProperty\\('effect'\\) \\(array\\|int\\|string\\|null\\) of encapsed string cannot be cast to string\\.$#"
4530-
count: 1
4531-
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
4532-
45334453
-
45344454
message: "#^Part \\$xAxis\\-\\>getShadowProperty\\(\\['color', 'type'\\]\\) \\(array\\|int\\|string\\|null\\) of encapsed string cannot be cast to string\\.$#"
45354455
count: 1

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3088,7 +3088,7 @@ public function setLocale(string $locale)
30883088
}
30893089

30903090
// Test whether we have any language data for this language (any locale)
3091-
if (in_array($language, self::$validLocaleLanguages)) {
3091+
if (in_array($language, self::$validLocaleLanguages, true)) {
30923092
// initialise language/locale settings
30933093
self::$localeFunctions = [];
30943094
self::$localeArgumentSeparator = ',';

src/PhpSpreadsheet/Calculation/Functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static function ifCondition($condition)
152152
if ($condition === '') {
153153
return '=""';
154154
}
155-
if (!is_string($condition) || !in_array($condition[0], ['>', '<', '='])) {
155+
if (!is_string($condition) || !in_array($condition[0], ['>', '<', '='], true)) {
156156
$condition = self::operandSpecialHandling($condition);
157157
if (is_bool($condition)) {
158158
return '=' . ($condition ? 'TRUE' : 'FALSE');

src/PhpSpreadsheet/Calculation/Information/ErrorValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function isError($value = '')
4747
return false;
4848
}
4949

50-
return in_array($value, ExcelError::$errorCodes) || $value === ExcelError::CALC();
50+
return in_array($value, ExcelError::$errorCodes, true) || $value === ExcelError::CALC();
5151
}
5252

5353
/**

src/PhpSpreadsheet/Calculation/Information/ExcelError.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ExcelError
1111
/**
1212
* List of error codes.
1313
*
14-
* @var array
14+
* @var array<string, string>
1515
*/
1616
public static $errorCodes = [
1717
'null' => '#NULL!',
@@ -60,7 +60,7 @@ public static function type($value = '')
6060
*
6161
* @return string #NULL!
6262
*/
63-
public static function null()
63+
public static function null(): string
6464
{
6565
return self::$errorCodes['null'];
6666
}
@@ -72,7 +72,7 @@ public static function null()
7272
*
7373
* @return string #NUM!
7474
*/
75-
public static function NAN()
75+
public static function NAN(): string
7676
{
7777
return self::$errorCodes['num'];
7878
}
@@ -84,7 +84,7 @@ public static function NAN()
8484
*
8585
* @return string #REF!
8686
*/
87-
public static function REF()
87+
public static function REF(): string
8888
{
8989
return self::$errorCodes['reference'];
9090
}
@@ -100,7 +100,7 @@ public static function REF()
100100
*
101101
* @return string #N/A!
102102
*/
103-
public static function NA()
103+
public static function NA(): string
104104
{
105105
return self::$errorCodes['na'];
106106
}
@@ -112,7 +112,7 @@ public static function NA()
112112
*
113113
* @return string #VALUE!
114114
*/
115-
public static function VALUE()
115+
public static function VALUE(): string
116116
{
117117
return self::$errorCodes['value'];
118118
}
@@ -124,7 +124,7 @@ public static function VALUE()
124124
*
125125
* @return string #NAME?
126126
*/
127-
public static function NAME()
127+
public static function NAME(): string
128128
{
129129
return self::$errorCodes['name'];
130130
}
@@ -134,17 +134,17 @@ public static function NAME()
134134
*
135135
* @return string #DIV/0!
136136
*/
137-
public static function DIV0()
137+
public static function DIV0(): string
138138
{
139139
return self::$errorCodes['divisionbyzero'];
140140
}
141141

142142
/**
143143
* CALC.
144144
*
145-
* @return string #Not Yet Implemented
145+
* @return string #CALC!
146146
*/
147-
public static function CALC()
147+
public static function CALC(): string
148148
{
149149
return '#CALC!';
150150
}

src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private static function hLookupSearch($lookupValue, array $lookupArray, $column,
7373
// break if we have passed possible keys
7474
$bothNumeric = is_numeric($lookupValue) && is_numeric($rowData);
7575
$bothNotNumeric = !is_numeric($lookupValue) && !is_numeric($rowData);
76-
$cellDataLower = StringHelper::strToLower($rowData);
76+
$cellDataLower = StringHelper::strToLower((string) $rowData);
7777

7878
if (
7979
$notExactMatch &&

src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static function vLookupSearch($lookupValue, array $lookupArray, $column,
9090
foreach ($lookupArray as $rowKey => $rowData) {
9191
$bothNumeric = is_numeric($lookupValue) && is_numeric($rowData[$column]);
9292
$bothNotNumeric = !is_numeric($lookupValue) && !is_numeric($rowData[$column]);
93-
$cellDataLower = StringHelper::strToLower($rowData[$column]);
93+
$cellDataLower = StringHelper::strToLower((string) $rowData[$column]);
9494

9595
// break if we have passed possible keys
9696
if (

src/PhpSpreadsheet/Cell/Cell.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ public function setValue($value)
202202
*
203203
* @param mixed $value Value
204204
* @param string $dataType Explicit data type, see DataType::TYPE_*
205+
* Note that PhpSpreadsheet does not validate that the value and datatype are consistent, in using this
206+
* method, then it is your responsibility as an end-user developer to validate that the value and
207+
* the datatype match.
208+
* If you do mismatch value and datatpe, then the value you enter may be changed to match the datatype
209+
* that you specify.
205210
*
206211
* @return Cell
207212
*/
@@ -210,7 +215,7 @@ public function setValueExplicit($value, $dataType)
210215
// set the value according to data type
211216
switch ($dataType) {
212217
case DataType::TYPE_NULL:
213-
$this->value = $value;
218+
$this->value = null;
214219

215220
break;
216221
case DataType::TYPE_STRING2:

src/PhpSpreadsheet/Cell/DataType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DataType
2121
/**
2222
* List of error codes.
2323
*
24-
* @var array
24+
* @var array<string, int>
2525
*/
2626
private static $errorCodes = [
2727
'#NULL!' => 0,
@@ -36,7 +36,7 @@ class DataType
3636
/**
3737
* Get list of error codes.
3838
*
39-
* @return array
39+
* @return array<string, int>
4040
*/
4141
public static function getErrorCodes()
4242
{
@@ -48,7 +48,7 @@ public static function getErrorCodes()
4848
*
4949
* @param null|RichText|string $textValue Value to sanitize to an Excel string
5050
*
51-
* @return null|RichText|string Sanitized value
51+
* @return RichText|string Sanitized value
5252
*/
5353
public static function checkString($textValue)
5454
{
@@ -58,7 +58,7 @@ public static function checkString($textValue)
5858
}
5959

6060
// string must never be longer than 32,767 characters, truncate if necessary
61-
$textValue = StringHelper::substring($textValue, 0, 32767);
61+
$textValue = StringHelper::substring((string) $textValue, 0, 32767);
6262

6363
// we require that newline is represented as "\n" in core, not as "\r\n" or "\r"
6464
$textValue = str_replace(["\r\n", "\r"], "\n", $textValue);

0 commit comments

Comments
 (0)