Skip to content

Commit 626b08f

Browse files
authored
Merge pull request PHPOffice#4026 from oleibman/stan9c
Better Definitions for Mixed Parameters and Values Part 2 of Many
2 parents d539dfa + 9ff79a6 commit 626b08f

File tree

20 files changed

+104
-63
lines changed

20 files changed

+104
-63
lines changed

src/PhpSpreadsheet/Collection/Cells.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function cloneCellCollection(Worksheet $worksheet): static
288288
$newCollection->index[$key] = $value;
289289
$stored = $newCollection->cache->set(
290290
$newCollection->cachePrefix . $key,
291-
clone $this->cache->get($this->cachePrefix . $key)
291+
clone $this->getCache($key)
292292
);
293293
if ($stored === false) {
294294
$this->destructIfNeeded($newCollection, 'Failed to copy cells in cache');
@@ -410,11 +410,7 @@ public function get(string $cellCoordinate): ?Cell
410410
return null;
411411
}
412412

413-
// Check if the entry that has been requested actually exists in the cache
414-
$cell = $this->cache->get($this->cachePrefix . $cellCoordinate);
415-
if ($cell === null) {
416-
throw new PhpSpreadsheetException("Cell entry {$cellCoordinate} no longer exists in cache. This probably means that the cache was cleared by someone else.");
417-
}
413+
$cell = $this->getcache($cellCoordinate);
418414

419415
// Set current entry to the requested entry
420416
$this->currentCoordinate = $cellCoordinate;
@@ -466,4 +462,14 @@ private function getAllCacheKeys(): iterable
466462
yield $this->cachePrefix . $coordinate;
467463
}
468464
}
465+
466+
private function getCache(string $cellCoordinate): Cell
467+
{
468+
$cell = $this->cache->get($this->cachePrefix . $cellCoordinate);
469+
if (!($cell instanceof Cell)) {
470+
throw new PhpSpreadsheetException("Cell entry {$cellCoordinate} no longer exists in cache. This probably means that the cache was cleared by someone else.");
471+
}
472+
473+
return $cell;
474+
}
469475
}

src/PhpSpreadsheet/Helper/Html.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Helper;
44

5+
use DOMAttr;
56
use DOMDocument;
67
use DOMElement;
78
use DOMNode;
@@ -708,6 +709,7 @@ protected function startFontTag(DOMElement $tag): void
708709
{
709710
$attrs = $tag->attributes;
710711
if ($attrs !== null) {
712+
/** @var DOMAttr $attribute */
711713
foreach ($attrs as $attribute) {
712714
$attributeName = strtolower($attribute->name);
713715
$attributeName = preg_replace('/^html:/', '', $attributeName) ?? $attributeName; // in case from Xml spreadsheet

src/PhpSpreadsheet/Helper/Sample.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,9 @@ public function getSamples(): array
8181
$regex = new RegexIterator($iterator, '/^.+\.php$/', RecursiveRegexIterator::GET_MATCH);
8282

8383
$files = [];
84+
/** @var string[] $file */
8485
foreach ($regex as $file) {
8586
$file = str_replace(str_replace('\\', '/', $baseDir) . '/', '', str_replace('\\', '/', $file[0]));
86-
if (is_array($file)) {
87-
// @codeCoverageIgnoreStart
88-
throw new RuntimeException('str_replace returned array');
89-
// @codeCoverageIgnoreEnd
90-
}
9187
$info = pathinfo($file);
9288
$category = str_replace('_', ' ', $info['dirname'] ?? '');
9389
$name = str_replace('_', ' ', (string) preg_replace('/(|\.php)/', '', $info['filename']));
@@ -254,10 +250,10 @@ public function logCalculationResult(
254250
?string $descriptionCell = null
255251
): void {
256252
if ($descriptionCell !== null) {
257-
$this->log($worksheet->getCell($descriptionCell)->getValue());
253+
$this->log($worksheet->getCell($descriptionCell)->getValueString());
258254
}
259-
$this->log($worksheet->getCell($formulaCell)->getValue());
260-
$this->log(sprintf('%s() Result is ', $functionName) . $worksheet->getCell($formulaCell)->getCalculatedValue());
255+
$this->log($worksheet->getCell($formulaCell)->getValueString());
256+
$this->log(sprintf('%s() Result is ', $functionName) . $worksheet->getCell($formulaCell)->getCalculatedValueString());
261257
}
262258

263259
/**

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Reader;
44

5+
use DOMAttr;
56
use DOMDocument;
67
use DOMElement;
78
use DOMNode;
@@ -289,6 +290,7 @@ protected function flushCell(Worksheet $sheet, string $column, int|string $row,
289290
private function processDomElementBody(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child): void
290291
{
291292
$attributeArray = [];
293+
/** @var DOMAttr $attribute */
292294
foreach ($child->attributes as $attribute) {
293295
$attributeArray[$attribute->name] = $attribute->value;
294296
}

src/PhpSpreadsheet/Reader/Slk.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ private function processCRecord(array $rowData, Spreadsheet &$spreadsheet, strin
268268
if ($sharedFormula === true && $sharedRow >= 0 && $sharedColumn >= 0) {
269269
$thisCoordinate = Coordinate::stringFromColumnIndex((int) $column) . $row;
270270
$sharedCoordinate = Coordinate::stringFromColumnIndex($sharedColumn) . $sharedRow;
271+
/** @var string */
271272
$formula = $spreadsheet->getActiveSheet()->getCell($sharedCoordinate)->getValue();
272273
$spreadsheet->getActiveSheet()->getCell($thisCoordinate)->setValue($formula);
273274
$referenceHelper = ReferenceHelper::getInstance();
@@ -281,6 +282,7 @@ private function processCRecord(array $rowData, Spreadsheet &$spreadsheet, strin
281282
return;
282283
}
283284
$columnLetter = Coordinate::stringFromColumnIndex((int) $column);
285+
/** @var string */
284286
$cellData = Calculation::unwrapResult($cellData);
285287

286288
// Set cell value

src/PhpSpreadsheet/Shared/Escher/DgContainer/SpgrContainer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public function getParent(): ?self
3232

3333
/**
3434
* Add a child. This will be either spgrContainer or spContainer.
35+
*
36+
* @param SpgrContainer|SpgrContainer\SpContainer $child child to be added
3537
*/
3638
public function addChild(mixed $child): void
3739
{

src/PhpSpreadsheet/Spreadsheet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function discardMacros(): void
253253
*/
254254
public function setRibbonXMLData(mixed $target, mixed $xmlData): void
255255
{
256-
if ($target !== null && $xmlData !== null) {
256+
if (is_string($target) && is_string($xmlData)) {
257257
$this->ribbonXMLData = ['target' => $target, 'data' => $xmlData];
258258
} else {
259259
$this->ribbonXMLData = null;

src/PhpSpreadsheet/Style/ConditionalFormatting/CellMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ protected function processDuplicatesComparison(Conditional $conditional): bool
235235
self::COMPARISON_DUPLICATES_OPERATORS[$conditional->getConditionType()],
236236
$worksheetName,
237237
$this->conditionalRange,
238-
$this->cellConditionCheck($this->cell->getCalculatedValue())
238+
$this->cellConditionCheck($this->cell->getCalculatedValueString())
239239
);
240240

241241
return $this->evaluateExpression($expression);

src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/CellValue.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected function operand(int $index, mixed $operand, string $operandValueType
6969
$this->operandValueType[$index] = $operandValueType;
7070
}
7171

72+
/** @param null|bool|float|int|string $value value to be wrapped */
7273
protected function wrapValue(mixed $value, string $operandValueType): float|int|string
7374
{
7475
if (!is_numeric($value) && !is_bool($value) && null !== $value) {
@@ -175,7 +176,9 @@ public function __call(string $methodName, array $arguments): self
175176
if (count($arguments) < 2) {
176177
$this->operand(0, $arguments[0]);
177178
} else {
178-
$this->operand(0, $arguments[0], $arguments[1]);
179+
/** @var string */
180+
$arg1 = $arguments[1];
181+
$this->operand(0, $arguments[0], $arg1);
179182
}
180183

181184
return $this;

src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/Expression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static function fromConditional(Conditional $conditional, string $cellRan
5454
}
5555

5656
/**
57-
* @param mixed[] $arguments
57+
* @param string[] $arguments
5858
*/
5959
public function __call(string $methodName, array $arguments): self
6060
{

0 commit comments

Comments
 (0)