Skip to content

Commit

Permalink
More @param to native types
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Dec 11, 2023
1 parent 4c2f380 commit bab6fc4
Show file tree
Hide file tree
Showing 52 changed files with 98 additions and 298 deletions.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,11 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Chart/DataSeriesValues.php

-
message: "#^Argument of an invalid type array\\<int, \\(SimpleXMLElement\\|null\\)\\>\\|SimpleXMLElement\\|null supplied for foreach, only iterables are supported\\.$#"
count: 2
path: src/PhpSpreadsheet/Reader/Xlsx/ConditionalStyles.php

-
message: "#^Cannot access property \\$color on SimpleXMLElement\\|null\\.$#"
count: 2
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5526,10 +5526,8 @@ private function getArgumentDefaultValue(ReflectionParameter $methodArgument): m

/**
* Add cell reference if needed while making sure that it is the last argument.
*
* @param array|string $functionCall
*/
private function addCellReference(array $args, bool $passCellReference, $functionCall, ?Cell $cell = null): array
private function addCellReference(array $args, bool $passCellReference, array|string $functionCall, ?Cell $cell = null): array
{
if ($passCellReference) {
if (is_array($functionCall)) {
Expand Down
5 changes: 1 addition & 4 deletions src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

abstract class DatabaseAbstract
{
/**
* @param null|int|string $field
*/
abstract public static function evaluate(array $database, $field, array $criteria): null|float|int|string;
abstract public static function evaluate(array $database, null|int|string $field, array $criteria): null|float|int|string;

/**
* fieldExtract.
Expand Down
7 changes: 2 additions & 5 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class Difference
* @param mixed $endDate Excel date serial value, PHP date/time stamp, PHP DateTime object
* or a standard date string
* Or can be an array of date values
* @param array|string $unit
* Or can be an array of unit values
* @param array|string $unit Or can be an array of unit values
*
* @return array|int|string Interval between the dates
* If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
Expand Down Expand Up @@ -80,10 +79,8 @@ private static function initialDiff(float $startDate, float $endDate): float

/**
* Decide whether it's time to set retVal.
*
* @param bool|int $retVal
*/
private static function replaceRetValue($retVal, string $unit, string $compare): null|bool|int
private static function replaceRetValue(bool|int $retVal, string $unit, string $compare): null|bool|int
{
if ($retVal !== false || $unit !== $compare) {
return $retVal;
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public static function dateParseSucceeded(array $dateArray): bool
*
* @param array|false $dateArray
*/
private static function forceArray($dateArray): array
private static function forceArray(array|bool $dateArray): array
{
return is_array($dateArray) ? $dateArray : ['error_count' => 1];
}
Expand Down
44 changes: 16 additions & 28 deletions src/PhpSpreadsheet/Calculation/Engineering/BitWise.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ class BitWise
/**
* Split a number into upper and lower portions for full 32-bit support.
*
* @param float|int $number
*
* @return int[]
*/
private static function splitNumber($number): array
private static function splitNumber(float|int $number): array
{
return [(int) floor($number / self::SPLIT_DIVISOR), (int) fmod($number, self::SPLIT_DIVISOR)];
}
Expand All @@ -32,15 +30,13 @@ private static function splitNumber($number): array
* Excel Function:
* BITAND(number1, number2)
*
* @param array|int $number1
* Or can be an array of values
* @param array|int $number2
* Or can be an array of values
* @param null|array|bool|float|int|string $number1 Or can be an array of values
* @param null|array|bool|float|int|string $number2 Or can be an array of values
*
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BITAND($number1, $number2): array|string|int
public static function BITAND(null|array|bool|float|int|string $number1, null|array|bool|float|int|string $number2): array|string|int
{
if (is_array($number1) || is_array($number2)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2);
Expand All @@ -66,15 +62,13 @@ public static function BITAND($number1, $number2): array|string|int
* Excel Function:
* BITOR(number1, number2)
*
* @param array|int $number1
* Or can be an array of values
* @param array|int $number2
* Or can be an array of values
* @param null|array|bool|float|int|string $number1 Or can be an array of values
* @param null|array|bool|float|int|string $number2 Or can be an array of values
*
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BITOR($number1, $number2): array|string|int
public static function BITOR(null|array|bool|float|int|string $number1, null|array|bool|float|int|string $number2): array|string|int
{
if (is_array($number1) || is_array($number2)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2);
Expand All @@ -101,15 +95,13 @@ public static function BITOR($number1, $number2): array|string|int
* Excel Function:
* BITXOR(number1, number2)
*
* @param array|int $number1
* Or can be an array of values
* @param array|int $number2
* Or can be an array of values
* @param null|array|bool|float|int|string $number1 Or can be an array of values
* @param null|array|bool|float|int|string $number2 Or can be an array of values
*
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BITXOR($number1, $number2): array|string|int
public static function BITXOR(null|array|bool|float|int|string $number1, null|array|bool|float|int|string $number2): array|string|int
{
if (is_array($number1) || is_array($number2)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2);
Expand All @@ -136,15 +128,13 @@ public static function BITXOR($number1, $number2): array|string|int
* Excel Function:
* BITLSHIFT(number, shift_amount)
*
* @param array|int $number
* Or can be an array of values
* @param array|int $shiftAmount
* Or can be an array of values
* @param null|array|bool|float|int|string $number Or can be an array of values
* @param null|array|bool|float|int|string $shiftAmount Or can be an array of values
*
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BITLSHIFT($number, $shiftAmount): array|string|float
public static function BITLSHIFT(null|array|bool|float|int|string $number, null|array|bool|float|int|string $shiftAmount): array|string|float
{
if (is_array($number) || is_array($shiftAmount)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $shiftAmount);
Expand Down Expand Up @@ -173,15 +163,13 @@ public static function BITLSHIFT($number, $shiftAmount): array|string|float
* Excel Function:
* BITRSHIFT(number, shift_amount)
*
* @param array|int $number
* Or can be an array of values
* @param array|int $shiftAmount
* Or can be an array of values
* @param null|array|bool|float|int|string $number Or can be an array of values
* @param null|array|bool|float|int|string $shiftAmount Or can be an array of values
*
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BITRSHIFT($number, $shiftAmount): array|string|float
public static function BITRSHIFT(null|array|bool|float|int|string $number, null|array|bool|float|int|string $shiftAmount): array|string|float
{
if (is_array($number) || is_array($shiftAmount)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $shiftAmount);
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/Engineering/Erf.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ private static function makeFloat(mixed $value): float

/**
* Method to calculate the erf value.
*
* @param float|int|string $value
*/
public static function erfValue($value): float
public static function erfValue(float|int|string $value): float
{
$value = (float) $value;
if (abs($value) > 2.2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

class CashFlowValidations extends FinancialValidations
{
/**
* @param mixed $rate
*/
public static function validateRate($rate): float
public static function validateRate(mixed $rate): float
{
$rate = self::validateFloat($rate);

Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ private static function operandSpecialHandling(mixed $operand): mixed
/**
* Convert a multi-dimensional array to a simple 1-dimensional array.
*
* @param array|mixed $array Array to be flattened
* @param mixed $array Array to be flattened
*
* @return array Flattened array
*/
public static function flattenArray($array): array
public static function flattenArray(mixed $array): array
{
if (!is_array($array)) {
return (array) $array;
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/LookupRef/Indirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ private static function a1Format(mixed $a1fmt): bool

/**
* Convert cellAddress to string, verify not null string.
*
* @param array|string $cellAddress
*/
private static function validateAddress($cellAddress): string
private static function validateAddress(array|string|null $cellAddress): string
{
$cellAddress = Functions::flattenSingleValue($cellAddress);
if (!is_string($cellAddress) || !$cellAddress) {
Expand Down
16 changes: 4 additions & 12 deletions src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ public static function validateNumericNullBool(mixed $number): int|float

/**
* Validate numeric, but allow substitute for null.
*
* @param null|float|int $substitute
*/
public static function validateNumericNullSubstitution(mixed $number, $substitute): float|int
public static function validateNumericNullSubstitution(mixed $number, null|float|int $substitute): float|int
{
$number = Functions::flattenSingleValue($number);
if ($number === null && $substitute !== null) {
Expand All @@ -57,10 +55,8 @@ public static function validateNumericNullSubstitution(mixed $number, $substitut

/**
* Confirm number >= 0.
*
* @param float|int $number
*/
public static function validateNotNegative($number, ?string $except = null): void
public static function validateNotNegative(float|int $number, ?string $except = null): void
{
if ($number >= 0) {
return;
Expand All @@ -71,10 +67,8 @@ public static function validateNotNegative($number, ?string $except = null): voi

/**
* Confirm number > 0.
*
* @param float|int $number
*/
public static function validatePositive($number, ?string $except = null): void
public static function validatePositive(float|int $number, ?string $except = null): void
{
if ($number > 0) {
return;
Expand All @@ -85,10 +79,8 @@ public static function validatePositive($number, ?string $except = null): void

/**
* Confirm number != 0.
*
* @param float|int $number
*/
public static function validateNotZero($number): void
public static function validateNotZero(float|int $number): void
{
if ($number) {
return;
Expand Down
8 changes: 3 additions & 5 deletions src/PhpSpreadsheet/Calculation/MathTrig/Operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ public static function mod(mixed $dividend, mixed $divisor): array|string|float
*
* Computes x raised to the power y.
*
* @param array|float|int $x
* Or can be an array of values
* @param array|float|int $y
* Or can be an array of values
* @param array|float|int|string $x Or can be an array of values
* @param array|float|int|string $y Or can be an array of values
*
* @return array|float|int|string The result, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function power($x, $y)
public static function power(array|float|int|string $x, array|float|int|string $y): array|float|int|string
{
if (is_array($x) || is_array($y)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $y);
Expand Down
8 changes: 3 additions & 5 deletions src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ class Trunc
*
* Truncates value to the number of fractional digits by number_digits.
*
* @param array|float $value
* Or can be an array of values
* @param array|int $digits
* Or can be an array of values
* @param array|float $value Or can be an array of values
* @param array|int $digits Or can be an array of values
*
* @return array|float|string Truncated value, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function evaluate($value = 0, $digits = 0)
public static function evaluate(array|float|string|null $value = 0, array|int|string $digits = 0): array|float|string
{
if (is_array($value) || is_array($digits)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $digits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public static function inverse(mixed $value)
* Calculates the probability that a member of a standard normal population will fall between
* the mean and z standard deviations from the mean.
*
* @param mixed $value
* Or can be an array of values
* @param mixed $value Or can be an array of values
*
* @return array|float|string The result, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
Expand Down
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/Chart/Axis.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ public function setAxisType(string $type): self

/**
* Set Fill Property.
*
* @param ?int $alpha
*/
public function setFillParameters(?string $color, ?int $alpha = null, ?string $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
{
Expand Down
6 changes: 0 additions & 6 deletions src/PhpSpreadsheet/Chart/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,6 @@ public function setTopLeftCell(string $cellAddress): static
/**
* Set the offset position within the Top Left cell for the chart.
*
* @param ?int $xOffset
* @param ?int $yOffset
*
* @return $this
*/
public function setTopLeftOffset(?int $xOffset, ?int $yOffset): static
Expand Down Expand Up @@ -514,9 +511,6 @@ public function getBottomRightCell(): string
/**
* Set the offset position within the Bottom Right cell for the chart.
*
* @param ?int $xOffset
* @param ?int $yOffset
*
* @return $this
*/
public function setBottomRightOffset(?int $xOffset, ?int $yOffset): static
Expand Down
11 changes: 2 additions & 9 deletions src/PhpSpreadsheet/Chart/ChartColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ public function setBrightness(?int $brightness): self
return $this;
}

/**
* @param null|float|int|string $alpha
* @param null|float|int|string $brightness
*/
public function setColorProperties(?string $color, $alpha = null, ?string $type = null, $brightness = null): self
public function setColorProperties(?string $color, null|float|int|string $alpha = null, ?string $type = null, null|float|int|string $brightness = null): self
{
if (empty($type) && !empty($color)) {
if (str_starts_with($color, '*')) {
Expand Down Expand Up @@ -157,10 +153,7 @@ public static function alphaToXml(int $alpha): string
return (string) (100 - $alpha) . '000';
}

/**
* @param float|int|string $alpha
*/
public static function alphaFromXml($alpha): int
public static function alphaFromXml(float|int|string $alpha): int
{
return 100 - ((int) $alpha / 1000);
}
Expand Down
6 changes: 1 addition & 5 deletions src/PhpSpreadsheet/Chart/DataSeriesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ public function getDataSource(): ?string
/**
* Set Series Data Source (formula).
*
* @param ?string $dataSource
*
* @return $this
*/
public function setDataSource(?string $dataSource): static
Expand Down Expand Up @@ -357,11 +355,9 @@ public function getLineWidth(): null|float|int
/**
* Set line width for the series.
*
* @param null|float|int $width
*
* @return $this
*/
public function setLineWidth($width): static
public function setLineWidth(null|float|int $width): static
{
$this->lineStyleProperties['width'] = $width;

Expand Down
Loading

0 comments on commit bab6fc4

Please sign in to comment.