Skip to content

Commit 130c6e9

Browse files
committed
More Phpstan 10 Prep
All of Calculation and Shared/OLE are left to tackle.
1 parent 3922d9a commit 130c6e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+351
-116
lines changed

src/PhpSpreadsheet/Cell/Cell.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ public function getCalculatedValue(bool $resetLog = true): mixed
464464
}
465465
}
466466
}
467+
/** @var string $newColumn */
467468
++$newColumn;
468469
}
469470
++$newRow;
@@ -502,6 +503,7 @@ public function getCalculatedValue(bool $resetLog = true): mixed
502503
$maxRow = (int) $matches[5];
503504
for ($row = $minRow; $row <= $maxRow; ++$row) {
504505
for ($col = $minCol; $col !== $maxCol; ++$col) {
506+
/** @var string $col */
505507
if ("$col$row" !== $coordinate) {
506508
$thisworksheet->getCell("$col$row")->setValue(null);
507509
}
@@ -524,8 +526,11 @@ public function getCalculatedValue(bool $resetLog = true): mixed
524526
$newColumn = $column;
525527
foreach ($resultRow as $resultValue) {
526528
if ($row !== $newRow || $column !== $newColumn) {
527-
$thisworksheet->getCell($newColumn . $newRow)->setValue($resultValue);
529+
$thisworksheet
530+
->getCell($newColumn . $newRow)
531+
->setValue($resultValue);
528532
}
533+
/** @var string $newColumn */
529534
++$newColumn;
530535
}
531536
++$newRow;
@@ -934,9 +939,7 @@ public function setXfIndex(int $indexValue): self
934939
/**
935940
* Set the formula attributes.
936941
*
937-
* @param $attributes null|array<string, string>
938-
*
939-
* @return $this
942+
* @param null|array<string, string> $attributes
940943
*/
941944
public function setFormulaAttributes(?array $attributes): self
942945
{

src/PhpSpreadsheet/Cell/CellAddress.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public static function fromColumnAndRow(int|string $columnId, int|string $rowId,
4848
return new self(Coordinate::stringFromColumnIndex($columnId) . $rowId, $worksheet);
4949
}
5050

51+
/** @param array<int, int> $array */
5152
public static function fromColumnRowArray(array $array, ?Worksheet $worksheet = null): self
5253
{
5354
[$columnId, $rowId] = $array;

src/PhpSpreadsheet/Cell/Coordinate.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,16 @@ public static function splitRange(string $range): array
170170
public static function buildRange(array $range): string
171171
{
172172
// Verify range
173-
if (empty($range) || !is_array($range[0])) {
173+
if (empty($range)) {
174174
throw new Exception('Range does not contain any information');
175175
}
176176

177177
// Build range
178178
$counter = count($range);
179179
for ($i = 0; $i < $counter; ++$i) {
180+
if (!is_array($range[$i])) {
181+
throw new Exception('Each array entry must be an array');
182+
}
180183
$range[$i] = implode(':', $range[$i]);
181184
}
182185

src/PhpSpreadsheet/Cell/RowRange.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __destruct()
2727
$this->worksheet = null;
2828
}
2929

30+
/** @param array{int, int} $array */
3031
public static function fromArray(array $array, ?Worksheet $worksheet = null): self
3132
{
3233
[$from, $to] = $array;

src/PhpSpreadsheet/Chart/DataSeriesValues.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class DataSeriesValues extends Properties
5353

5454
/**
5555
* Data Values.
56+
*
57+
* @var null|mixed[]
5658
*/
5759
private ?array $dataValues;
5860

@@ -75,6 +77,7 @@ class DataSeriesValues extends Properties
7577
/**
7678
* Create a new DataSeriesValues object.
7779
*
80+
* @param null|mixed[] $dataValues
7881
* @param null|ChartColor|ChartColor[]|string|string[] $fillColor
7982
*/
8083
public function __construct(
@@ -347,7 +350,10 @@ private function validateColor(string $color): bool
347350
*/
348351
public function getLineWidth(): null|float|int
349352
{
350-
return $this->lineStyleProperties['width'];
353+
/** @var null|float|int */
354+
$temp = $this->lineStyleProperties['width'];
355+
356+
return $temp;
351357
}
352358

353359
/**
@@ -381,6 +387,7 @@ public function multiLevelCount(): int
381387
{
382388
$levelCount = 0;
383389
foreach (($this->dataValues ?? []) as $dataValueSet) {
390+
/** @var mixed[] $dataValueSet */
384391
$levelCount = max($levelCount, count($dataValueSet));
385392
}
386393

@@ -389,6 +396,8 @@ public function multiLevelCount(): int
389396

390397
/**
391398
* Get Series Data Values.
399+
*
400+
* @return null|mixed[]
392401
*/
393402
public function getDataValues(): ?array
394403
{
@@ -416,6 +425,8 @@ public function getDataValue(): mixed
416425
/**
417426
* Set Series Data Values.
418427
*
428+
* @param mixed[] $dataValues
429+
*
419430
* @return $this
420431
*/
421432
public function setDataValues(array $dataValues): static
@@ -451,8 +462,9 @@ public function refresh(Worksheet $worksheet, bool $flatten = true): void
451462
if (($dimensions[0] == 1) || ($dimensions[1] == 1)) {
452463
$this->dataValues = Functions::flattenArray($newDataValues);
453464
} else {
454-
/** @var array<int, array> */
465+
/** @var array<int, mixed[]> */
455466
$newDataValuesx = $newDataValues;
467+
/** @var mixed[][] $newArray */
456468
$newArray = array_values(array_shift($newDataValuesx) ?? []);
457469
foreach ($newArray as $i => $newDataSet) {
458470
$newArray[$i] = [$newDataSet];
@@ -467,7 +479,7 @@ public function refresh(Worksheet $worksheet, bool $flatten = true): void
467479
$this->dataValues = $newArray;
468480
}
469481
}
470-
$this->pointCount = count($this->dataValues);
482+
$this->pointCount = count($this->dataValues ?? []);
471483
}
472484
}
473485

src/PhpSpreadsheet/Chart/Layout.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ class Layout
101101

102102
/**
103103
* Create a new Layout.
104+
*
105+
* @param array<mixed> $layout
104106
*/
105107
public function __construct(array $layout = [])
106108
{
109+
/** @var array{layoutTarget?: string, xMode?: string, yMode?: string, x?: float, y?: float, w?:float, h?:float, dLblPos?: string, labelFont?: ?mixed, labelFontColor?: ?mixed, labelEffects?: ?mixed, numFmtCode?: string} $layout */
107110
if (isset($layout['layoutTarget'])) {
108111
$this->layoutTarget = $layout['layoutTarget'];
109112
}
@@ -155,13 +158,15 @@ public function __construct(array $layout = [])
155158
}
156159
}
157160

161+
/** @param mixed[] $layout */
158162
private function initBoolean(array $layout, string $name): void
159163
{
160164
if (isset($layout[$name])) {
161165
$this->$name = (bool) $layout[$name];
162166
}
163167
}
164168

169+
/** @param mixed[] $layout */
165170
private function initColor(array $layout, string $name): void
166171
{
167172
if (isset($layout[$name]) && $layout[$name] instanceof ChartColor) {

src/PhpSpreadsheet/Chart/Properties.php

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ abstract class Properties
109109

110110
protected ChartColor $glowColor;
111111

112+
/** @var array{size: ?float} */
112113
protected array $softEdges = [
113114
'size' => null,
114115
];
115116

117+
/** @var mixed[] */
116118
protected array $shadowProperties = self::PRESETS_OPTIONS[0];
117119

118120
protected ChartColor $shadowColor;
@@ -395,13 +397,17 @@ protected function setColorProperties(?string $color, null|float|int|string $alp
395397
],
396398
];
397399

400+
/** @return mixed[] */
398401
protected function getShadowPresetsMap(int $presetsOption): array
399402
{
400403
return self::PRESETS_OPTIONS[$presetsOption] ?? self::PRESETS_OPTIONS[0];
401404
}
402405

403406
/**
404407
* Get value of array element.
408+
*
409+
* @param mixed[] $properties
410+
* @param array<mixed>|int|string $elements
405411
*/
406412
protected function getArrayElementsValue(array $properties, array|int|string $elements): mixed
407413
{
@@ -411,7 +417,7 @@ protected function getArrayElementsValue(array $properties, array|int|string $el
411417
}
412418

413419
foreach ($elements as $keys) {
414-
$reference = &$reference[$keys];
420+
$reference = &$reference[$keys]; //* @phpstan-ignore-line
415421
}
416422

417423
return $reference;
@@ -436,6 +442,10 @@ public function setGlowProperties(float $size, ?string $colorValue = null, ?int
436442

437443
/**
438444
* Get Glow Property.
445+
*
446+
* @param mixed[]|string $property
447+
*
448+
* @return null|array<mixed>|float|int|string
439449
*/
440450
public function getGlowProperty(array|string $property): null|array|float|int|string
441451
{
@@ -449,7 +459,9 @@ public function getGlowProperty(array|string $property): null|array|float|int|st
449459
'alpha' => $this->glowColor->getColorProperty('alpha'),
450460
];
451461
} elseif (is_array($property) && count($property) >= 2 && $property[0] === 'color') {
452-
$retVal = $this->glowColor->getColorProperty($property[1]);
462+
/** @var string */
463+
$temp = $property[1];
464+
$retVal = $this->glowColor->getColorProperty($temp);
453465
}
454466

455467
return $retVal;
@@ -566,6 +578,9 @@ protected function setShadowPresetsProperties(int $presets)
566578
/**
567579
* Set Shadow Properties Values.
568580
*
581+
* @param mixed[] $propertiesMap
582+
* @param null|mixed[] $reference
583+
*
569584
* @return $this
570585
*/
571586
protected function setShadowPropertiesMapValues(array $propertiesMap, ?array &$reference = null)
@@ -574,8 +589,13 @@ protected function setShadowPropertiesMapValues(array $propertiesMap, ?array &$r
574589
foreach ($propertiesMap as $property_key => $property_val) {
575590
if (is_array($property_val)) {
576591
if (in_array($property_key, self::SHADOW_ARRAY_KEYS, true)) {
577-
$reference = &$this->shadowProperties[$property_key];
578-
$this->setShadowPropertiesMapValues($property_val, $reference);
592+
/** @var null|array<mixed> */
593+
$temp = &$this->shadowProperties[$property_key];
594+
$reference = &$temp;
595+
$this->setShadowPropertiesMapValues(
596+
$property_val,
597+
$reference
598+
);
579599
}
580600
} else {
581601
if ($base_reference === null) {
@@ -640,6 +660,8 @@ public function getShadowColorObject(): ChartColor
640660
* Get Shadow Property.
641661
*
642662
* @param string|string[] $elements
663+
*
664+
* @return null|mixed[]|string
643665
*/
644666
public function getShadowProperty($elements): array|string|null
645667
{
@@ -662,6 +684,7 @@ public function getShadowProperty($elements): array|string|null
662684
return $retVal;
663685
}
664686

687+
/** @return mixed[] */
665688
public function getShadowArray(): array
666689
{
667690
$array = $this->shadowProperties;
@@ -674,6 +697,7 @@ public function getShadowArray(): array
674697

675698
protected ChartColor $lineColor;
676699

700+
/** @var array{width: null|float|int|string, compound: ?string, dash: ?string, cap: ?string, join: ?string, arrow: array{head: array{type: ?string, size: null|int|string, w: ?string, len: ?string}, end: array{type: ?string, size: null|int|string, w: ?string, len: ?string}}} */
677701
protected array $lineStyleProperties = [
678702
'width' => null, //'9525',
679703
'compound' => '', //self::LINE_STYLE_COMPOUND_SIMPLE,
@@ -798,13 +822,16 @@ public function setLineStyleProperties(
798822
}
799823
}
800824

825+
/** @return mixed[] */
801826
public function getLineStyleArray(): array
802827
{
803828
return $this->lineStyleProperties;
804829
}
805830

831+
/** @param mixed[] $lineStyleProperties */
806832
public function setLineStyleArray(array $lineStyleProperties = []): self
807833
{
834+
/** @var array{width?: ?string, compound?: string, dash?: string, cap?: string, join?: string, arrow?: array{head?: array{type?: string, size?: int, w?: string, len?: string}, end?: array{type?: string, size?: int, w?: string, len?: string}}} $lineStyleProperties */
808835
$this->activateObject();
809836
$this->lineStyleProperties['width'] = $lineStyleProperties['width'] ?? null;
810837
$this->lineStyleProperties['compound'] = $lineStyleProperties['compound'] ?? '';
@@ -826,13 +853,15 @@ public function setLineStyleArray(array $lineStyleProperties = []): self
826853
public function setLineStyleProperty(string $propertyName, mixed $value): self
827854
{
828855
$this->activateObject();
829-
$this->lineStyleProperties[$propertyName] = $value;
856+
$this->lineStyleProperties[$propertyName] = $value; //* @phpstan-ignore-line
830857

831858
return $this;
832859
}
833860

834861
/**
835862
* Get Line Style Property.
863+
*
864+
* @param array<mixed>|string $elements
836865
*/
837866
public function getLineStyleProperty(array|string $elements): ?string
838867
{
@@ -873,7 +902,7 @@ protected function getLineStyleArrowSize(int $arraySelector, string $arrayKaySel
873902
*/
874903
public function getLineStyleArrowParameters(string $arrowSelector, string $propertySelector): string
875904
{
876-
return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrowSelector]['size'], $propertySelector);
905+
return $this->getLineStyleArrowSize((int) $this->lineStyleProperties['arrow'][$arrowSelector]['size'], $propertySelector);
877906
}
878907

879908
/**

src/PhpSpreadsheet/Chart/Title.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Title
3636

3737
/**
3838
* Create a new Title.
39+
*
40+
* @param array<RichText|string>|RichText|string $caption
3941
*/
4042
public function __construct(array|RichText|string $caption = '', ?Layout $layout = null, bool $overlay = false)
4143
{
@@ -86,6 +88,8 @@ public function getCaptionText(?Spreadsheet $spreadsheet = null): string
8688
/**
8789
* Set caption.
8890
*
91+
* @param array<RichText|string>|RichText|string $caption
92+
*
8993
* @return $this
9094
*/
9195
public function setCaption(array|RichText|string $caption): static
@@ -161,11 +165,11 @@ public function __clone()
161165
$this->layout = ($this->layout === null) ? null : clone $this->layout;
162166
$this->font = ($this->font === null) ? null : clone $this->font;
163167
if (is_array($this->caption)) {
164-
$captions = $this->caption;
165-
$this->caption = [];
166-
foreach ($captions as $caption) {
167-
$this->caption[] = is_object($caption) ? (clone $caption) : $caption;
168+
$captions = [];
169+
foreach ($this->caption as $caption) {
170+
$captions[] = is_object($caption) ? (clone $caption) : $caption;
168171
}
172+
$this->caption = $captions;
169173
} else {
170174
$this->caption = is_object($this->caption) ? (clone $this->caption) : $this->caption;
171175
}

src/PhpSpreadsheet/Collection/Cells.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function getCurrentRow(): int
185185
/**
186186
* Get highest worksheet column and highest row that have cell records.
187187
*
188-
* @return array Highest column name and highest row number
188+
* @return array{row: int, column: string} Highest column name and highest row number
189189
*/
190190
public function getHighestRowAndColumn(): array
191191
{
@@ -387,6 +387,7 @@ public function add(string $cellCoordinate, Cell $cell): Cell
387387
$column = 0;
388388
$row = '';
389389
sscanf($cellCoordinate, '%[A-Z]%d', $column, $row);
390+
/** @var int $row */
390391
$this->index[$cellCoordinate] = (--$row * self::MAX_COLUMN_ID) + Coordinate::columnIndexFromString((string) $column);
391392

392393
$this->currentCoordinate = $cellCoordinate;

0 commit comments

Comments
 (0)