Skip to content

Commit 0ef98ac

Browse files
authored
Merge branch 'master' into Row/Column_isEmpty-check
2 parents b62de98 + e3471f8 commit 0ef98ac

22 files changed

+1332
-559
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2525

2626
### Changed
2727

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

3032
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 & 47 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
@@ -4467,12 +4427,12 @@ parameters:
44674427

44684428
-
44694429
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, array\\|int\\|string given\\.$#"
4470-
count: 8
4430+
count: 2
44714431
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
44724432

44734433
-
44744434
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, array\\|int\\|string\\|null given\\.$#"
4475-
count: 2
4435+
count: 1
44764436
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
44774437

44784438
-
@@ -4515,11 +4475,6 @@ parameters:
45154475
count: 2
45164476
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
45174477

4518-
-
4519-
message: "#^Part \\$xAxis\\-\\>getShadowProperty\\('effect'\\) \\(array\\|int\\|string\\|null\\) of encapsed string cannot be cast to string\\.$#"
4520-
count: 1
4521-
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
4522-
45234478
-
45244479
message: "#^Part \\$xAxis\\-\\>getShadowProperty\\(\\['color', 'type'\\]\\) \\(array\\|int\\|string\\|null\\) of encapsed string cannot be cast to string\\.$#"
45254480
count: 1

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/PhpSpreadsheet/Chart/Axis.php

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,7 @@ class Axis extends Properties
8989
*
9090
* @var mixed[]
9191
*/
92-
private $shadowProperties = [
93-
'presets' => self::SHADOW_PRESETS_NOSHADOW,
94-
'effect' => null,
95-
'color' => [
96-
'type' => self::EXCEL_COLOR_TYPE_STANDARD,
97-
'value' => 'black',
98-
'alpha' => 40,
99-
],
100-
'size' => [
101-
'sx' => null,
102-
'sy' => null,
103-
'kx' => null,
104-
],
105-
'blur' => null,
106-
'direction' => null,
107-
'distance' => null,
108-
'algn' => null,
109-
'rotWithShape' => null,
110-
];
92+
private $shadowProperties = Properties::PRESETS_OPTIONS[0];
11193

11294
/**
11395
* Glow Properties.
@@ -340,6 +322,20 @@ public function getLineStyleArrowLength($arrow)
340322
return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'len');
341323
}
342324

325+
/**
326+
* @param mixed $value
327+
*/
328+
public function setShadowProperty(string $propertyName, $value): self
329+
{
330+
if ($propertyName === 'color' && is_array($value)) {
331+
$this->setShadowColor($value['value'], $value['alpha'], $value['type']);
332+
} else {
333+
$this->shadowProperties[$propertyName] = $value;
334+
}
335+
336+
return $this;
337+
}
338+
343339
/**
344340
* Set Shadow Properties.
345341
*
@@ -379,6 +375,8 @@ private function setShadowPresetsProperties($presets)
379375
return $this;
380376
}
381377

378+
private const SHADOW_ARRAY_KEYS = ['size', 'color'];
379+
382380
/**
383381
* Set Shadow Properties from Mapped Values.
384382
*
@@ -391,12 +389,10 @@ private function setShadowPropertiesMapValues(array $propertiesMap, &$reference
391389
$base_reference = $reference;
392390
foreach ($propertiesMap as $property_key => $property_val) {
393391
if (is_array($property_val)) {
394-
if ($reference === null) {
392+
if (in_array($property_key, self::SHADOW_ARRAY_KEYS, true)) {
395393
$reference = &$this->shadowProperties[$property_key];
396-
} else {
397-
$reference = &$reference[$property_key];
394+
$this->setShadowPropertiesMapValues($property_val, $reference);
398395
}
399-
$this->setShadowPropertiesMapValues($property_val, $reference);
400396
} else {
401397
if ($base_reference === null) {
402398
$this->shadowProperties[$property_key] = $property_val;
@@ -435,7 +431,7 @@ private function setShadowColor($color, $alpha, $alphaType)
435431
private function setShadowBlur($blur)
436432
{
437433
if ($blur !== null) {
438-
$this->shadowProperties['blur'] = (string) $this->getExcelPointsWidth($blur);
434+
$this->shadowProperties['blur'] = $blur;
439435
}
440436

441437
return $this;
@@ -444,14 +440,14 @@ private function setShadowBlur($blur)
444440
/**
445441
* Set Shadow Angle.
446442
*
447-
* @param null|int $angle
443+
* @param null|float|int $angle
448444
*
449445
* @return $this
450446
*/
451447
private function setShadowAngle($angle)
452448
{
453-
if ($angle !== null) {
454-
$this->shadowProperties['direction'] = (string) $this->getExcelPointsAngle($angle);
449+
if (is_numeric($angle)) {
450+
$this->shadowProperties['direction'] = $angle;
455451
}
456452

457453
return $this;
@@ -467,7 +463,7 @@ private function setShadowAngle($angle)
467463
private function setShadowDistance($distance)
468464
{
469465
if ($distance !== null) {
470-
$this->shadowProperties['distance'] = (string) $this->getExcelPointsWidth($distance);
466+
$this->shadowProperties['distance'] = $distance;
471467
}
472468

473469
return $this;
@@ -525,7 +521,7 @@ public function getGlowProperty($property)
525521
private function setGlowSize($size)
526522
{
527523
if ($size !== null) {
528-
$this->glowProperties['size'] = $this->getExcelPointsWidth($size);
524+
$this->glowProperties['size'] = $size;
529525
}
530526

531527
return $this;
@@ -555,7 +551,7 @@ private function setGlowColor($color, $alpha, $colorType)
555551
public function setSoftEdges($size): void
556552
{
557553
if ($size !== null) {
558-
$this->softEdges['size'] = (string) $this->getExcelPointsWidth($size);
554+
$this->softEdges['size'] = $size;
559555
}
560556
}
561557

0 commit comments

Comments
 (0)