diff --git a/phpstan.neon.dist b/phpstan.neon.dist index de7dee8645..e6d7d0d33c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -23,6 +23,7 @@ parameters: parallel: processTimeout: 300.0 checkMissingIterableValueType: false + checkGenericClassInNonGenericObjectType: false ignoreErrors: # Accept a bit anything for assert methods - '~^Parameter \#2 .* of static method PHPUnit\\Framework\\Assert\:\:assert\w+\(\) expects .*, .* given\.$~' diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index d0e1220348..63b52505b7 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -195,7 +195,7 @@ public static function getLocaleBoolean(string $index): string * Excel constant string translations to their PHP equivalents * Constant conversion from text name/value to actual (datatyped) value. * - * @var array + * @var array */ private static array $excelConstants = [ 'TRUE' => true, @@ -208,7 +208,7 @@ public static function keyInExcelConstants(string $key): bool return array_key_exists($key, self::$excelConstants); } - public static function getExcelConstants(string $key): mixed + public static function getExcelConstants(string $key): bool|null { return self::$excelConstants[$key]; } diff --git a/src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php b/src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php index 3f40d475a9..7d9885ee90 100644 --- a/src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php +++ b/src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php @@ -156,7 +156,7 @@ private static function executeQuery(array $database, string $query, array $crit return $database; } - private static function processCondition(string $criterion, array $fields, array $dataValues, string $conditions): mixed + private static function processCondition(string $criterion, array $fields, array $dataValues, string $conditions): string { $key = array_search($criterion, $fields, true); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php index 20b48969be..088e3794c7 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; +use DateTime; use DateTimeImmutable; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; @@ -21,10 +22,10 @@ class Current * Excel Function: * TODAY() * - * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, + * @return DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function today(): mixed + public static function today(): DateTime|float|int|string { $dti = new DateTimeImmutable(); $dateArray = Helpers::dateParse($dti->format('c')); @@ -46,10 +47,10 @@ public static function today(): mixed * Excel Function: * NOW() * - * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, + * @return DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function now(): mixed + public static function now(): DateTime|float|int|string { $dti = new DateTimeImmutable(); $dateArray = Helpers::dateParse($dti->format('c')); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php index c9c6458819..e0e4b25f88 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; +use DateTime; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; @@ -58,12 +59,12 @@ class Date * example, DATE(2008,1,-15) returns the serial number representing * December 16, 2007. * - * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, + * @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag * 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 fromYMD(array|float|int|string $year, array|float|int|string $month, array|float|int|string $day): mixed + public static function fromYMD(array|float|int|string $year, array|float|int|string $month, array|float|int|string $day): float|int|DateTime|string|array { if (is_array($year) || is_array($month) || is_array($day)) { return self::evaluateArrayArguments([self::class, __FUNCTION__], $year, $month, $day); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php index 4bf75dd3dc..8c5fa71c94 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; +use DateTime; use DateTimeImmutable; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; @@ -34,12 +35,12 @@ class DateValue * #VALUE! error value if date_text is out of this range. * Or can be an array of date values * - * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, + * @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag * 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|float $dateValue): mixed + public static function fromString(null|array|string|int|bool|float $dateValue): array|string|float|int|DateTime { if (is_array($dateValue)) { return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $dateValue); @@ -131,10 +132,10 @@ private static function setUpArray(string $dateValue, DateTimeImmutable $dti): a /** * Final results. * - * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, + * @return DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - private static function finalResults(array $PHPDateArray, DateTimeImmutable $dti, int $baseYear): mixed + private static function finalResults(array $PHPDateArray, DateTimeImmutable $dti, int $baseYear): string|float|int|DateTime { $retValue = ExcelError::Value(); if (Helpers::dateParseSucceeded($PHPDateArray)) { diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php index 733cecb614..94ffa4c4d3 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php @@ -58,12 +58,13 @@ public static function getDateValue(mixed $dateValue, bool $allowBool = true): f /** * getTimeValue. * - * @return mixed Excel date/time serial value, or string if error + * @return float|string Excel date/time serial value, or string if error */ - public static function getTimeValue(string $timeValue): mixed + public static function getTimeValue(string $timeValue): string|float { $saveReturnDateType = Functions::getReturnDateType(); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); + /** @var float|string $timeValue */ $timeValue = TimeValue::fromString($timeValue); Functions::setReturnDateType($saveReturnDateType); @@ -238,6 +239,8 @@ public static function validateNumericNull(mixed $number): int|float /** * Many functions accept null/false/true argument treated as 0/0/1. + * + * @phpstan-assert float $number */ public static function validateNotNegative(mixed $number): float { diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php index f653c2fe40..a90c051734 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php @@ -73,12 +73,12 @@ public static function adjust(mixed $dateValue, array|string|bool|float|int $adj * a negative value yields a past date. * Or can be an array of adjustment values * - * @return array|mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, + * @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag * If an array of values is passed as the argument, then the returned result will also be an array * with the same dimensions */ - public static function lastDay(mixed $dateValue, array|float|int|bool|string $adjustmentMonths): mixed + public static function lastDay(mixed $dateValue, array|float|int|bool|string $adjustmentMonths): array|string|DateTime|float|int { if (is_array($dateValue) || is_array($adjustmentMonths)) { return self::evaluateArrayArguments([self::class, __FUNCTION__], $dateValue, $adjustmentMonths); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php index 011f41773c..4e4ed3c853 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php @@ -31,12 +31,12 @@ class WorkDay * Or can be an array of int values * @param null|mixed $dateArgs An array of dates (such as holidays) to exclude from the calculation * - * @return array|mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, + * @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag * If an array of values is passed for the $startDate or $endDays,arguments, then the returned result * will also be an array with matching dimensions */ - public static function date(mixed $startDate, array|int|string $endDays, mixed ...$dateArgs): mixed + public static function date(mixed $startDate, array|int|string $endDays, mixed ...$dateArgs): array|float|int|DateTime|string { if (is_array($startDate) || is_array($endDays)) { return self::evaluateArrayArgumentsSubset( diff --git a/src/PhpSpreadsheet/Calculation/Functions.php b/src/PhpSpreadsheet/Calculation/Functions.php index e838ef9cbb..6b74500698 100644 --- a/src/PhpSpreadsheet/Calculation/Functions.php +++ b/src/PhpSpreadsheet/Calculation/Functions.php @@ -277,7 +277,7 @@ public static function flattenArrayIndexed($array): array * * @param mixed $value Array or scalar value */ - public static function flattenSingleValue(mixed $value = ''): mixed + public static function flattenSingleValue(mixed $value): mixed { while (is_array($value)) { $value = array_shift($value); diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php b/src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php index 30db8437ed..455442a8eb 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php @@ -18,9 +18,9 @@ class Hyperlink * @param mixed $displayName Expect string. Value to return when testValue is an error condition * @param ?Cell $cell The cell to set the hyperlink in * - * @return mixed The value of $displayName (or $linkURL if $displayName was blank) + * @return string The value of $displayName (or $linkURL if $displayName was blank) */ - public static function set(mixed $linkURL = '', mixed $displayName = null, ?Cell $cell = null): mixed + public static function set(mixed $linkURL = '', mixed $displayName = null, ?Cell $cell = null): string { $linkURL = ($linkURL === null) ? '' : Functions::flattenSingleValue($linkURL); $displayName = ($displayName === null) ? '' : Functions::flattenSingleValue($displayName); diff --git a/src/PhpSpreadsheet/Calculation/Statistical/MaxMinBase.php b/src/PhpSpreadsheet/Calculation/Statistical/MaxMinBase.php index c575721872..a722fbd9c8 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/MaxMinBase.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/MaxMinBase.php @@ -4,7 +4,7 @@ abstract class MaxMinBase { - protected static function datatypeAdjustmentAllowStrings(mixed $value): mixed + protected static function datatypeAdjustmentAllowStrings(int|float|string|bool $value): int|float { if (is_bool($value)) { return (int) $value; diff --git a/src/PhpSpreadsheet/Calculation/Statistical/VarianceBase.php b/src/PhpSpreadsheet/Calculation/Statistical/VarianceBase.php index db6e691726..d5646cf9bc 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/VarianceBase.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/VarianceBase.php @@ -6,7 +6,7 @@ abstract class VarianceBase { - protected static function datatypeAdjustmentAllowStrings(mixed $value): mixed + protected static function datatypeAdjustmentAllowStrings(int|float|string|bool $value): int|float { if (is_bool($value)) { return (int) $value; diff --git a/src/PhpSpreadsheet/Calculation/TextData/Format.php b/src/PhpSpreadsheet/Calculation/TextData/Format.php index 38679379fb..67101ca1d0 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Format.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Format.php @@ -126,6 +126,7 @@ 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); } diff --git a/src/PhpSpreadsheet/Cell/AddressRange.php b/src/PhpSpreadsheet/Cell/AddressRange.php index 0217504b58..22e9d11ecc 100644 --- a/src/PhpSpreadsheet/Cell/AddressRange.php +++ b/src/PhpSpreadsheet/Cell/AddressRange.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Cell; +/** + * @template T + */ interface AddressRange { public const MAX_ROW = 1048576; @@ -10,8 +13,14 @@ interface AddressRange public const MAX_COLUMN_INT = 16384; + /** + * @return T + */ public function from(): mixed; + /** + * @return T + */ public function to(): mixed; public function __toString(): string; diff --git a/src/PhpSpreadsheet/Cell/CellRange.php b/src/PhpSpreadsheet/Cell/CellRange.php index c3445637de..677009dbe2 100644 --- a/src/PhpSpreadsheet/Cell/CellRange.php +++ b/src/PhpSpreadsheet/Cell/CellRange.php @@ -6,6 +6,9 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use Stringable; +/** + * @implements AddressRange + */ class CellRange implements AddressRange, Stringable { protected CellAddress $from; diff --git a/src/PhpSpreadsheet/Cell/ColumnRange.php b/src/PhpSpreadsheet/Cell/ColumnRange.php index e25b9b7e67..7f32a05c28 100644 --- a/src/PhpSpreadsheet/Cell/ColumnRange.php +++ b/src/PhpSpreadsheet/Cell/ColumnRange.php @@ -5,6 +5,9 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use Stringable; +/** + * @implements AddressRange + */ class ColumnRange implements AddressRange, Stringable { protected ?Worksheet $worksheet; diff --git a/src/PhpSpreadsheet/Cell/RowRange.php b/src/PhpSpreadsheet/Cell/RowRange.php index cb2f6b0e86..4ed232a931 100644 --- a/src/PhpSpreadsheet/Cell/RowRange.php +++ b/src/PhpSpreadsheet/Cell/RowRange.php @@ -5,6 +5,9 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use Stringable; +/** + * @implements AddressRange + */ class RowRange implements AddressRange, Stringable { protected ?Worksheet $worksheet; diff --git a/src/PhpSpreadsheet/Shared/StringHelper.php b/src/PhpSpreadsheet/Shared/StringHelper.php index 67fba22fee..18f8d0273b 100644 --- a/src/PhpSpreadsheet/Shared/StringHelper.php +++ b/src/PhpSpreadsheet/Shared/StringHelper.php @@ -636,9 +636,9 @@ public static function SYLKtoUTF8(string $textValue): string * Retrieve any leading numeric part of a string, or return the full string if no leading numeric * (handles basic integer or float, but not exponent or non decimal). * - * @return mixed string or only the leading numeric part of the string + * @return float|string string or only the leading numeric part of the string */ - public static function testStringAsNumeric(string $textValue): mixed + public static function testStringAsNumeric(string $textValue): float|string { if (is_numeric($textValue)) { return $textValue; diff --git a/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormatValueObject.php b/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormatValueObject.php index 43f480804b..e6d1035f4e 100644 --- a/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormatValueObject.php +++ b/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormatValueObject.php @@ -8,9 +8,9 @@ class ConditionalFormatValueObject private null|float|int|string $value; - private mixed $cellFormula; + private ?string $cellFormula; - public function __construct(string $type, null|float|int|string $value = null, mixed $cellFormula = null) + public function __construct(string $type, null|float|int|string $value = null, ?string $cellFormula = null) { $this->type = $type; $this->value = $value; @@ -41,12 +41,12 @@ public function setValue(null|float|int|string $value): self return $this; } - public function getCellFormula(): mixed + public function getCellFormula(): ?string { return $this->cellFormula; } - public function setCellFormula(mixed $cellFormula): self + public function setCellFormula(?string $cellFormula): self { $this->cellFormula = $cellFormula; diff --git a/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php b/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php index c4ef7eb620..c6c648ba24 100644 --- a/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php +++ b/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php @@ -162,12 +162,12 @@ private static function parseExtDataBarElementChildrenFromXml(ConditionalDataBar } } - public function getId(): mixed + public function getId(): string { return $this->id; } - public function setId(mixed $id): self + public function setId(string $id): self { $this->id = $id; diff --git a/src/PhpSpreadsheet/Writer/Xls/Parser.php b/src/PhpSpreadsheet/Writer/Xls/Parser.php index 3b078b4344..c51b490c92 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Parser.php +++ b/src/PhpSpreadsheet/Writer/Xls/Parser.php @@ -1246,9 +1246,9 @@ private function parenthesizedExpression(): array * It parses a term. It assumes the following rule: * Term -> Fact [("*" | "/") Fact]. * - * @return mixed The parsed ptg'd tree on success + * @return array The parsed ptg'd tree on success */ - private function term(): mixed + private function term(): array { $result = $this->fact(); while ( @@ -1277,9 +1277,9 @@ private function term(): mixed * | Number * | Function. * - * @return mixed The parsed ptg'd tree on success + * @return array The parsed ptg'd tree on success */ - private function fact(): mixed + private function fact(): array { $currentToken = $this->currentToken; if ($currentToken === '(') { @@ -1376,9 +1376,9 @@ private function fact(): mixed * It parses a function call. It assumes the following rule: * Func -> ( Expr [,Expr]* ). * - * @return mixed The parsed ptg'd tree on success + * @return array The parsed ptg'd tree on success */ - private function func(): mixed + private function func(): array { $num_args = 0; // number of arguments received $function = strtoupper($this->currentToken);