Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
parameters:
ignoreErrors:
-
message: "#^Binary operation \"/\" between float and array\\|float\\|int\\|string results in an error\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TimeValue
* Excel Function:
* TIMEVALUE(timeValue)
*
* @param null|array|bool|int|string $timeValue A text string that represents a time in any one of the Microsoft
* @param null|array|bool|float|int|string $timeValue A text string that represents a time in any one of the Microsoft
* Excel time formats; for example, "6:45 PM" and "18:45" text strings
* within quotation marks that represent time.
* Date information in time_text is ignored.
Expand All @@ -36,7 +36,7 @@ class TimeValue
* If an array of numbers is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/
public static function fromString(null|array|string|int|bool $timeValue): array|string|Datetime|int|float
public static function fromString(null|array|string|int|bool|float $timeValue): array|string|Datetime|int|float
{
if (is_array($timeValue)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $timeValue);
Expand Down
20 changes: 16 additions & 4 deletions src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ public static function withoutRepetition(mixed $numObjs, mixed $numInSet): array
return $e->getMessage();
}

return round(Factorial::fact($numObjs) / Factorial::fact($numObjs - $numInSet)) / Factorial::fact($numInSet); // @phpstan-ignore-line
/** @var float */
$quotient = Factorial::fact($numObjs);
/** @var float */
$divisor1 = Factorial::fact($numObjs - $numInSet);
/** @var float */
$divisor2 = Factorial::fact($numInSet);

return round($quotient / ($divisor1 * $divisor2));
}

/**
Expand Down Expand Up @@ -84,8 +91,13 @@ public static function withRepetition(mixed $numObjs, mixed $numInSet): array|in
return $e->getMessage();
}

return round(
Factorial::fact($numObjs + $numInSet - 1) / Factorial::fact($numObjs - 1) // @phpstan-ignore-line
) / Factorial::fact($numInSet);
/** @var float */
$quotient = Factorial::fact($numObjs + $numInSet - 1);
/** @var float */
$divisor1 = Factorial::fact($numObjs - 1);
/** @var float */
$divisor2 = Factorial::fact($numInSet);

return round($quotient / ($divisor1 * $divisor2));
}
}
5 changes: 3 additions & 2 deletions src/PhpSpreadsheet/Calculation/Statistical/Permutations.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ public static function PERMUT(mixed $numObjs, mixed $numInSet)
if ($numObjs < $numInSet) {
return ExcelError::NAN();
}
/** @var float|int|string */
$result1 = MathTrig\Factorial::fact($numObjs);
if (is_string($result1)) {
return $result1;
}
/** @var float|int|string */
$result2 = MathTrig\Factorial::fact($numObjs - $numInSet);
if (is_string($result2)) {
return $result2;
}
// phpstan thinks result1 and result2 can be arrays; they can't.
$result = round($result1 / $result2); // @phpstan-ignore-line
$result = round($result1 / $result2);

return IntOrFloat::evaluate($result);
}
Expand Down
8 changes: 4 additions & 4 deletions src/PhpSpreadsheet/Calculation/Statistical/Trends.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static function FORECAST(mixed $xValue, array $yValues, array $xValues)
* @param mixed[] $newValues Values of X for which we want to find Y
* @param mixed $const A logical (boolean) value specifying whether to force the intersect to equal 0 or not
*
* @return float[]
* @return array<int, array<int, array<int, float>>>
*/
public static function GROWTH(array $yValues, array $xValues = [], array $newValues = [], mixed $const = true): array
{
Expand All @@ -167,7 +167,7 @@ public static function GROWTH(array $yValues, array $xValues = [], array $newVal
$returnArray[0][] = [$bestFitExponential->getValueOfYForX($xValue)];
}

return $returnArray; //* @phpstan-ignore-line
return $returnArray;
}

/**
Expand Down Expand Up @@ -401,7 +401,7 @@ public static function STEYX(array $yValues, array $xValues): float|string
* @param mixed[] $newValues Values of X for which we want to find Y
* @param mixed $const A logical (boolean) value specifying whether to force the intersect to equal 0 or not
*
* @return float[]
* @return array<int, array<int, array<int, float>>>
*/
public static function TREND(array $yValues, array $xValues = [], array $newValues = [], mixed $const = true): array
{
Expand All @@ -420,6 +420,6 @@ public static function TREND(array $yValues, array $xValues = [], array $newValu
$returnArray[0][] = [$bestFitLinear->getValueOfYForX($xValue)];
}

return $returnArray; //* @phpstan-ignore-line
return $returnArray;
}
}
5 changes: 3 additions & 2 deletions src/PhpSpreadsheet/Calculation/TextData/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ public static function TEXTFORMAT(mixed $value, mixed $format): array|string
$format = Helpers::extractString($format);

if (!is_numeric($value) && Date::isDateTimeFormatCode($format)) {
// @phpstan-ignore-next-line
$value = DateTimeExcel\DateValue::fromString($value) + DateTimeExcel\TimeValue::fromString($value);
$value1 = DateTimeExcel\DateValue::fromString($value);
$value2 = DateTimeExcel\TimeValue::fromString($value);
$value = (is_numeric($value1) && is_numeric($value2)) ? ($value1 + $value2) : (is_numeric($value1) ? $value2 : $value1);
}

return (string) NumberFormat::toFormattedString($value, $format);
Expand Down
4 changes: 3 additions & 1 deletion src/PhpSpreadsheet/Cell/AdvancedValueBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public function bindValue(Cell $cell, mixed $value = null): bool
// Convert value to number
$sign = ($matches['PrefixedSign'] ?? $matches['PrefixedSign2'] ?? $matches['PostfixedSign']) ?? null;
$currencyCode = $matches['PrefixedCurrency'] ?? $matches['PostfixedCurrency'];
$value = (float) ($sign . trim(str_replace([$decimalSeparatorNoPreg, $currencyCode, ' ', '-'], ['.', '', '', ''], preg_replace('/(\d)' . $thousandsSeparator . '(\d)/u', '$1$2', $value)))); // @phpstan-ignore-line
/** @var string */
$temp = str_replace([$decimalSeparatorNoPreg, $currencyCode, ' ', '-'], ['.', '', '', ''], preg_replace('/(\d)' . $thousandsSeparator . '(\d)/u', '$1$2', $value));
$value = (float) ($sign . trim($temp));

return $this->setCurrency($value, $cell, $currencyCode ?? '');
}
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Document/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ public function setLastModifiedBy(string $modifiedBy): self
return $this;
}

private static function intOrFloatTimestamp(null|float|int|string $timestamp): float|int
private static function intOrFloatTimestamp(null|bool|float|int|string $timestamp): float|int
{
if ($timestamp === null) {
if ($timestamp === null || is_bool($timestamp)) {
$timestamp = (float) (new DateTime())->format('U');
} elseif (is_string($timestamp)) {
if (is_numeric($timestamp)) {
Expand Down Expand Up @@ -468,7 +468,7 @@ private static function convertProperty2(bool|int|float|string|null $propertyVal
case self::PROPERTY_TYPE_FLOAT:
return (float) $propertyValue;
case self::PROPERTY_TYPE_DATE:
return self::intOrFloatTimestamp($propertyValue); // @phpstan-ignore-line
return self::intOrFloatTimestamp($propertyValue);
case self::PROPERTY_TYPE_BOOLEAN:
return is_bool($propertyValue) ? $propertyValue : ($propertyValue === 'true');
default: // includes string
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/HashTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class HashTable
*
* @param T[] $source Optional source array to create HashTable from
*/
public function __construct(?array $source = null)
public function __construct(?array $source = [])
{
if ($source !== null) {
// Create HashTable
Expand Down
1 change: 1 addition & 0 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
if (isset($item->formula1)) {
$childNode = $node->addChild('formula1');
if ($childNode !== null) { // null should never happen
// see https://github.com/phpstan/phpstan/issues/8236
$childNode[0] = (string) $item->formula1->children(Namespaces::DATA_VALIDATIONS2)->f; // @phpstan-ignore-line
}
}
Expand Down
41 changes: 30 additions & 11 deletions src/PhpSpreadsheet/Reader/Xlsx/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ private function chartDataSeries(SimpleXMLElement $chartDetail, string $plotType
$multiSeriesType = null;
$smoothLine = false;
$seriesLabel = $seriesCategory = $seriesValues = $plotOrder = $seriesBubbles = [];
$plotDirection = null;

$seriesDetailSet = $chartDetail->children($this->cNamespace);
foreach ($seriesDetailSet as $seriesDetailKey => $seriesDetails) {
Expand Down Expand Up @@ -604,11 +605,16 @@ private function chartDataSeries(SimpleXMLElement $chartDetail, string $plotType
break;
case 'order':
$seriesOrder = self::getAttributeInteger($seriesDetail, 'val');
$plotOrder[$seriesIndex] = $seriesOrder;
if ($seriesOrder !== null) {
$plotOrder[$seriesIndex] = $seriesOrder;
}

break;
case 'tx':
$seriesLabel[$seriesIndex] = $this->chartDataSeriesValueSet($seriesDetail);
$temp = $this->chartDataSeriesValueSet($seriesDetail);
if ($temp !== null) {
$seriesLabel[$seriesIndex] = $temp;
}

break;
case 'spPr':
Expand Down Expand Up @@ -685,27 +691,42 @@ private function chartDataSeries(SimpleXMLElement $chartDetail, string $plotType

break;
case 'smooth':
$smoothLine = self::getAttributeBoolean($seriesDetail, 'val');
$smoothLine = self::getAttributeBoolean($seriesDetail, 'val') ?? false;

break;
case 'cat':
$seriesCategory[$seriesIndex] = $this->chartDataSeriesValueSet($seriesDetail);
$temp = $this->chartDataSeriesValueSet($seriesDetail);
if ($temp !== null) {
$seriesCategory[$seriesIndex] = $temp;
}

break;
case 'val':
$seriesValues[$seriesIndex] = $this->chartDataSeriesValueSet($seriesDetail, "$marker", $fillColor, "$pointSize");
$temp = $this->chartDataSeriesValueSet($seriesDetail, "$marker", $fillColor, "$pointSize");
if ($temp !== null) {
$seriesValues[$seriesIndex] = $temp;
}

break;
case 'xVal':
$seriesCategory[$seriesIndex] = $this->chartDataSeriesValueSet($seriesDetail, "$marker", $fillColor, "$pointSize");
$temp = $this->chartDataSeriesValueSet($seriesDetail, "$marker", $fillColor, "$pointSize");
if ($temp !== null) {
$seriesCategory[$seriesIndex] = $temp;
}

break;
case 'yVal':
$seriesValues[$seriesIndex] = $this->chartDataSeriesValueSet($seriesDetail, "$marker", $fillColor, "$pointSize");
$temp = $this->chartDataSeriesValueSet($seriesDetail, "$marker", $fillColor, "$pointSize");
if ($temp !== null) {
$seriesValues[$seriesIndex] = $temp;
}

break;
case 'bubbleSize':
$seriesBubbles[$seriesIndex] = $this->chartDataSeriesValueSet($seriesDetail, "$marker", $fillColor, "$pointSize");
$seriesBubble = $this->chartDataSeriesValueSet($seriesDetail, "$marker", $fillColor, "$pointSize");
if ($seriesBubble !== null) {
$seriesBubbles[$seriesIndex] = $seriesBubble;
}

break;
case 'bubble3D':
Expand Down Expand Up @@ -819,9 +840,7 @@ private function chartDataSeries(SimpleXMLElement $chartDetail, string $plotType
}
}
}
/** @phpstan-ignore-next-line */
$series = new DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $smoothLine);
/** @phpstan-ignore-next-line */
$series = new DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $plotDirection, $smoothLine);
$series->setPlotBubbleSizes($seriesBubbles);

return $series;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class BSE

/**
* The parent BLIP Store Entry Container.
* Property is never currently read.
* Property is currently unused.
*/
private BstoreContainer $parent; // @phpstan-ignore-line
private BstoreContainer $parent;

/**
* The BLIP (Big Large Image or Picture).
Expand All @@ -43,6 +43,11 @@ public function setParent(BstoreContainer $parent): void
$this->parent = $parent;
}

public function getParent(): BstoreContainer
{
return $this->parent;
}

/**
* Get the BLIP.
*/
Expand Down
8 changes: 6 additions & 2 deletions src/PhpSpreadsheet/Style/NumberFormat/NumberFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,12 @@ private static function pregReplace(string $pattern, string $replacement, string

public static function padValue(string $value, string $baseFormat): string
{
/** @phpstan-ignore-next-line */
[$preDecimal, $postDecimal] = preg_split('/\.(?=(?:[^"]*"[^"]*")*[^"]*\Z)/miu', $baseFormat . '.?');
$preDecimal = $postDecimal = '';
$pregArray = preg_split('/\.(?=(?:[^"]*"[^"]*")*[^"]*\Z)/miu', $baseFormat . '.?');
if (is_array($pregArray)) {
$preDecimal = $pregArray[0] ?? '';
$postDecimal = $pregArray[1] ?? '';
}

$length = strlen($value);
if (str_contains($postDecimal, '?')) {
Expand Down
5 changes: 3 additions & 2 deletions src/PhpSpreadsheet/Worksheet/AutoFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1001,9 +1001,10 @@ public function showHideRows(): static
foreach ($columnFilterTests as $columnID => $columnFilterTest) {
$cellValue = $this->workSheet->getCell($columnID . $row)->getCalculatedValue();
// Execute the filter test
/** @var callable */
$temp = [self::class, $columnFilterTest['method']];
$result // $result && // phpstan says $result is always true here
// @phpstan-ignore-next-line
= call_user_func_array([self::class, $columnFilterTest['method']], [$cellValue, $columnFilterTest['arguments']]);
= call_user_func_array($temp, [$cellValue, $columnFilterTest['arguments']]);
// If filter test has resulted in FALSE, exit the loop straightaway rather than running any more tests
if (!$result) {
break;
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Worksheet/MemoryDrawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private static function identifyMimeTypeUsingGd(string $temporaryFileName): ?str
if (function_exists('getimagesize')) {
$imageSize = @getimagesize($temporaryFileName);
if (is_array($imageSize)) {
$mimeType = $imageSize['mime'] ?? null; // @phpstan-ignore-line
$mimeType = $imageSize['mime'];

return self::supportedMimeTypes($mimeType);
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Worksheet/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ private function updateStructuredReferencesInNamedFormulae(Spreadsheet $spreadsh
foreach ($spreadsheet->getNamedFormulae() as $namedFormula) {
$formula = $namedFormula->getValue();
if (preg_match($pattern, $formula) === 1) {
$formula = preg_replace($pattern, "{$newName}[", $formula);
$namedFormula->setValue($formula); // @phpstan-ignore-line
$formula = preg_replace($pattern, "{$newName}[", $formula) ?? '';
$namedFormula->setValue($formula);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Worksheet/Table/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ private static function updateStructuredReferencesInNamedFormulae(Spreadsheet $s
foreach ($spreadsheet->getNamedFormulae() as $namedFormula) {
$formula = $namedFormula->getValue();
if (preg_match($pattern, $formula) === 1) {
$formula = preg_replace($pattern, "[$1{$newTitle}]", $formula);
$namedFormula->setValue($formula); // @phpstan-ignore-line
$formula = preg_replace($pattern, "[$1{$newTitle}]", $formula) ?? '';
$namedFormula->setValue($formula);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Writer/Ods/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static function writeDocPropsCustom(XMLWriter $objWriter, Spreadsheet $s
case Properties::PROPERTY_TYPE_INTEGER:
case Properties::PROPERTY_TYPE_FLOAT:
$objWriter->writeAttribute('meta:value-type', 'float');
$objWriter->writeRawData($propertyValue); // @phpstan-ignore-line
$objWriter->writeRawData((string) $propertyValue);

break;
case Properties::PROPERTY_TYPE_BOOLEAN:
Expand All @@ -106,12 +106,12 @@ private static function writeDocPropsCustom(XMLWriter $objWriter, Spreadsheet $s
break;
case Properties::PROPERTY_TYPE_DATE:
$objWriter->writeAttribute('meta:value-type', 'date');
$dtobj = Date::dateTimeFromTimestamp($propertyValue ?? 0); // @phpstan-ignore-line
$dtobj = Date::dateTimeFromTimestamp((string) ($propertyValue ?? 0));
$objWriter->writeRawData($dtobj->format(DATE_W3C));

break;
default:
$objWriter->writeRawData($propertyValue); // @phpstan-ignore-line
$objWriter->writeRawData((string) $propertyValue);

break;
}
Expand Down
Loading