Skip to content

Commit

Permalink
Merge pull request #3873 from PHPOffice/powerkiki
Browse files Browse the repository at this point in the history
Remove all `mixed` in param type where reasonable (except Calculcation/)
  • Loading branch information
PowerKiKi authored Jan 22, 2024
2 parents 5faaf26 + b9901c3 commit a83e9fb
Show file tree
Hide file tree
Showing 28 changed files with 80 additions and 89 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org).

## Unreleased - TBD

### MINOR BREAKING CHANGE
### BREAKING CHANGE

- Typing was strengthened by leveraging native typing. While this should not change any behavior, it might need minor
adaption of your code if you use static analysis tools such as PHPStan or
Psalm. [PR #3718](https://github.com/PHPOffice/PhpSpreadsheet/pull/3718)
- Typing was strengthened by leveraging native typing. This should not change any behavior. However, if you implement
any interfaces or inherit from any classes, you will need to adapt your typing accordingly. If you use static analysis
tools such as PHPStan or Psalm, new errors might be found. If you find actual bugs because of the new typing, please
open a PR that fixes it with a **detailed** explanation of the reason. We'll try to merge and release typing-related
fixes quickly in the coming days. [PR #3718](https://github.com/PHPOffice/PhpSpreadsheet/pull/3718)
- All deprecated things have been removed, for details, see [816b91d0b4](https://github.com/PHPOffice/PhpSpreadsheet/commit/816b91d0b4a0c7285a9e3fc88c58f7730d922044)

### Added

Expand All @@ -33,7 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Changed

- Drop support for PHP 7.4, according to https://phpspreadsheet.readthedocs.io/en/latest/#php-version-support [PR #3713](https://github.com/PHPOffice/PhpSpreadsheet/pull/3713)
- **Drop support for PHP 7.4**, according to https://phpspreadsheet.readthedocs.io/en/latest/#php-version-support [PR #3713](https://github.com/PHPOffice/PhpSpreadsheet/pull/3713)
- RLM Added to NumberFormatter Currency. This happens depending on release of ICU which Php is using (it does not yet happen with any official release). PhpSpreadsheet will continue to use the value returned by Php, but a method is added to keep the result unchanged from release to release. [Issue #3571](https://github.com/PHPOffice/PhpSpreadsheet/issues/3571) [PR #3640](https://github.com/PHPOffice/PhpSpreadsheet/pull/3640)
- `toFormattedString` will now always return a string. This was introduced with 1.28.0, but was not properly documented at the time. This can affect the results of `toArray`, `namedRangeToArray`, and `rangeToArray`. [PR #3304](https://github.com/PHPOffice/PhpSpreadsheet/pull/3304)
- Value of constants FORMAT_CURRENCY_EUR and FORMAT_CURRENCY_USD was changed in 1.28.0, but was not properly documented at the time. [Issue #3577](https://github.com/PHPOffice/PhpSpreadsheet/issues/3577)
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Cell/AdvancedValueBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder
* @param Cell $cell Cell to bind value to
* @param mixed $value Value to bind in cell
*/
public function bindValue(Cell $cell, $value = null): bool
public function bindValue(Cell $cell, mixed $value = null): bool
{
if ($value === null) {
return parent::bindValue($cell, $value);
Expand Down
8 changes: 4 additions & 4 deletions src/PhpSpreadsheet/Cell/CellAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ public function __destruct()
* @phpstan-assert int|numeric-string $columnId
* @phpstan-assert int|numeric-string $rowId
*/
private static function validateColumnAndRow(mixed $columnId, mixed $rowId): void
private static function validateColumnAndRow(int|string $columnId, int|string $rowId): void
{
if (!is_numeric($columnId) || $columnId <= 0 || !is_numeric($rowId) || $rowId <= 0) {
throw new Exception('Row and Column Ids must be positive integer values');
}
}

public static function fromColumnAndRow(mixed $columnId, mixed $rowId, ?Worksheet $worksheet = null): self
public static function fromColumnAndRow(int|string $columnId, int|string $rowId, ?Worksheet $worksheet = null): self
{
self::validateColumnAndRow($columnId, $rowId);

return new self(Coordinate::stringFromColumnIndex($columnId) . ((string) $rowId), $worksheet);
return new self(Coordinate::stringFromColumnIndex($columnId) . $rowId, $worksheet);
}

public static function fromColumnRowArray(array $array, ?Worksheet $worksheet = null): self
Expand All @@ -55,7 +55,7 @@ public static function fromColumnRowArray(array $array, ?Worksheet $worksheet =
return self::fromColumnAndRow($columnId, $rowId, $worksheet);
}

public static function fromCellAddress(mixed $cellAddress, ?Worksheet $worksheet = null): self
public static function fromCellAddress(string $cellAddress, ?Worksheet $worksheet = null): self
{
return new self($cellAddress, $worksheet);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Cell/DefaultValueBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DefaultValueBinder implements IValueBinder
* @param Cell $cell Cell to bind value to
* @param mixed $value Value to bind in cell
*/
public function bindValue(Cell $cell, $value): bool
public function bindValue(Cell $cell, mixed $value): bool
{
// sanitize UTF-8 strings
if (is_string($value)) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Cell/StringValueBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function setConversionForAllValueTypes(bool $suppressConversion = false):
* @param Cell $cell Cell to bind value to
* @param mixed $value Value to bind in cell
*/
public function bindValue(Cell $cell, $value): bool
public function bindValue(Cell $cell, mixed $value): bool
{
if (is_object($value)) {
return $this->bindObjectValue($cell, $value);
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Chart/Axis.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public function __construct()
/**
* Get Series Data Type.
*/
public function setAxisNumberProperties(mixed $format_code, ?bool $numeric = null, int $sourceLinked = 0): void
public function setAxisNumberProperties(string $format_code, ?bool $numeric = null, int $sourceLinked = 0): void
{
$format = (string) $format_code;
$format = $format_code;
$this->axisNumber['format'] = $format;
$this->axisNumber['source_linked'] = $sourceLinked;
if (is_bool($numeric)) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Chart/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Chart
* Create a new Chart.
* majorGridlines and minorGridlines are deprecated, moved to Axis.
*/
public function __construct(mixed $name, ?Title $title = null, ?Legend $legend = null, ?PlotArea $plotArea = null, mixed $plotVisibleOnly = true, string $displayBlanksAs = DataSeries::EMPTY_AS_GAP, ?Title $xAxisLabel = null, ?Title $yAxisLabel = null, ?Axis $xAxis = null, ?Axis $yAxis = null, ?GridLines $majorGridlines = null, ?GridLines $minorGridlines = null)
public function __construct(string $name, ?Title $title = null, ?Legend $legend = null, ?PlotArea $plotArea = null, bool $plotVisibleOnly = true, string $displayBlanksAs = DataSeries::EMPTY_AS_GAP, ?Title $xAxisLabel = null, ?Title $yAxisLabel = null, ?Axis $xAxis = null, ?Axis $yAxis = null, ?GridLines $majorGridlines = null, ?GridLines $minorGridlines = null)
{
$this->name = $name;
$this->title = $title;
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Chart/DataSeries.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function getPlotLabels(): array
*
* @return DataSeriesValues|false
*/
public function getPlotLabelByIndex(mixed $index): bool|DataSeriesValues
public function getPlotLabelByIndex(int $index): bool|DataSeriesValues
{
$keys = array_keys($this->plotLabel);
if (in_array($index, $keys)) {
Expand All @@ -257,7 +257,7 @@ public function getPlotCategories(): array
*
* @return DataSeriesValues|false
*/
public function getPlotCategoryByIndex(mixed $index): bool|DataSeriesValues
public function getPlotCategoryByIndex(int $index): bool|DataSeriesValues
{
$keys = array_keys($this->plotCategory);
if (in_array($index, $keys)) {
Expand Down Expand Up @@ -304,7 +304,7 @@ public function getPlotValues(): array
*
* @return DataSeriesValues|false
*/
public function getPlotValuesByIndex(mixed $index): bool|DataSeriesValues
public function getPlotValuesByIndex(int $index): bool|DataSeriesValues
{
$keys = array_keys($this->plotValues);
if (in_array($index, $keys)) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Chart/PlotArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getPlotGroup(): array
/**
* Get Plot Series by Index.
*/
public function getPlotGroupByIndex(mixed $index): DataSeries
public function getPlotGroupByIndex(int $index): DataSeries
{
return $this->plotSeries[$index];
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Chart/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ protected function getShadowPresetsMap(int $presetsOption): array
/**
* Get value of array element.
*/
protected function getArrayElementsValue(mixed $properties, mixed $elements): mixed
protected function getArrayElementsValue(array $properties, array|int|string $elements): mixed
{
$reference = &$properties;
if (!is_array($elements)) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Helper/Dimension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Dimension
* Phpstan bug has been fixed; this function allows us to
* pass Phpstan whether fixed or not.
*/
private static function stanBugFixed(mixed $value): array
private static function stanBugFixed(array|int|null $value): array
{
return is_array($value) ? $value : [null, null];
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ private function applyInlineStyle(Worksheet &$sheet, int $row, string $column, a
/**
* Check if has #, so we can get clean hex.
*/
public function getStyleColor(mixed $value): string
public function getStyleColor(?string $value): string
{
$value = (string) $value;
if (str_starts_with($value, '#')) {
Expand Down
6 changes: 2 additions & 4 deletions src/PhpSpreadsheet/Reader/Xls/Escher.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ class Escher

/**
* The object to be returned by the reader. Modified during load.
*
* @var BSE|BstoreContainer|DgContainer|DggContainer|\PhpOffice\PhpSpreadsheet\Shared\Escher|SpContainer|SpgrContainer
*/
private $object;
private BSE|BstoreContainer|DgContainer|DggContainer|\PhpOffice\PhpSpreadsheet\Shared\Escher|SpContainer|SpgrContainer $object;

/**
* Create a new Escher instance.
*/
public function __construct(mixed $object)
public function __construct(BSE|BstoreContainer|DgContainer|DggContainer|\PhpOffice\PhpSpreadsheet\Shared\Escher|SpContainer|SpgrContainer $object)
{
$this->object = $object;
}
Expand Down
5 changes: 3 additions & 2 deletions src/PhpSpreadsheet/Reader/Xlsx/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public function readChart(SimpleXMLElement $chartElements, string $chartName): \
$chartElementsC = $chartElements->children($this->cNamespace);

$XaxisLabel = $YaxisLabel = $legend = $title = null;
$dispBlanksAs = $plotVisOnly = null;
$dispBlanksAs = null;
$plotVisOnly = false;
$plotArea = null;
$rotX = $rotY = $rAngAx = $perspective = null;
$xAxis = new Axis();
Expand Down Expand Up @@ -381,7 +382,7 @@ public function readChart(SimpleXMLElement $chartElements, string $chartName): \

break;
case 'plotVisOnly':
$plotVisOnly = self::getAttributeString($chartDetails, 'val');
$plotVisOnly = (bool) self::getAttributeString($chartDetails, 'val');

break;
case 'dispBlanksAs':
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Reader/Xlsx/Styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ public function styles(): array
*
* @param mixed $array (usually array, in theory can be false)
*/
private static function getArrayItem(mixed $array, int $key = 0): ?SimpleXMLElement
private static function getArrayItem(mixed $array): ?SimpleXMLElement
{
return is_array($array) ? ($array[$key] ?? null) : null;
return is_array($array) ? ($array[0] ?? null) : null;
}
}
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Xlsx/WorkbookView.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(Spreadsheet $spreadsheet)
$this->spreadsheet = $spreadsheet;
}

public function viewSettings(SimpleXMLElement $xmlWorkbook, mixed $mainNS, array $mapSheetId, bool $readDataOnly): void
public function viewSettings(SimpleXMLElement $xmlWorkbook, string $mainNS, array $mapSheetId, bool $readDataOnly): void
{
// Default active sheet index to the first loaded worksheet from the file
$this->spreadsheet->setActiveSheetIndex(0);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Shared/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static function convertIsoDate(mixed $value): float|int
*
* @return DateTime PHP date/time object
*/
public static function excelToDateTimeObject($excelTimestamp, $timeZone = null): DateTime
public static function excelToDateTimeObject(float|int $excelTimestamp, null|DateTimeZone|string $timeZone = null): DateTime
{
$timeZone = ($timeZone === null) ? self::getDefaultTimezone() : self::validateTimeZone($timeZone);
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_EXCEL) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Shared/OLE/PPS.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function getPpsWk(): string
*
* @return int The index for this PPS
*/
public static function savePpsSetPnt(array &$raList, mixed $to_save, mixed $depth = 0): int
public static function savePpsSetPnt(array &$raList, mixed $to_save, int $depth = 0): int
{
if (!is_array($to_save) || (empty($to_save))) {
return 0xFFFFFFFF;
Expand Down
18 changes: 4 additions & 14 deletions src/PhpSpreadsheet/Spreadsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ public function getRibbonXMLData(string $what = 'all'): null|array|string //we n
/**
* store binaries ribbon objects (pictures).
*/
public function setRibbonBinObjects(mixed $BinObjectsNames, mixed $BinObjectsData): void
public function setRibbonBinObjects(mixed $binObjectsNames, mixed $binObjectsData): void
{
if ($BinObjectsNames !== null && $BinObjectsData !== null) {
$this->ribbonBinObjects = ['names' => $BinObjectsNames, 'data' => $BinObjectsData];
if ($binObjectsNames !== null && $binObjectsData !== null) {
$this->ribbonBinObjects = ['names' => $binObjectsNames, 'data' => $binObjectsData];
} else {
$this->ribbonBinObjects = null;
}
Expand Down Expand Up @@ -318,16 +318,6 @@ public function setUnparsedLoadedData(array $unparsedLoadedData): void
$this->unparsedLoadedData = $unparsedLoadedData;
}

/**
* return the extension of a filename. Internal use for a array_map callback (php<5.3 don't like lambda function).
*/
private function getExtensionOnly(mixed $path): string
{
$extension = pathinfo($path, PATHINFO_EXTENSION);

return substr($extension, 0);
}

/**
* retrieve Binaries Ribbon Objects.
*/
Expand All @@ -351,7 +341,7 @@ public function getRibbonBinObjects(string $what = 'all'): ?array
&& isset($this->ribbonBinObjects['data']) && is_array($this->ribbonBinObjects['data'])
) {
$tmpTypes = array_keys($this->ribbonBinObjects['data']);
$ReturnData = array_unique(array_map([$this, 'getExtensionOnly'], $tmpTypes));
$ReturnData = array_unique(array_map(fn (string $path): string => pathinfo($path, PATHINFO_EXTENSION), $tmpTypes));
} else {
$ReturnData = []; // the caller want an array... not null if empty
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Worksheet/AutoFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function setEvaluated(bool $value): void
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
* or an AddressRange object.
*/
public function __construct($range = '', ?Worksheet $worksheet = null)
public function __construct(AddressRange|string|array $range = '', ?Worksheet $worksheet = null)
{
if ($range !== '') {
[, $range] = Worksheet::extractSheetTitle(Validations::validateCellRange($range), true);
Expand Down Expand Up @@ -105,7 +105,7 @@ public function getRange(): string
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
* or an AddressRange object.
*/
public function setRange($range = ''): self
public function setRange(AddressRange|string|array $range = ''): self
{
$this->evaluated = false;
// extract coordinate
Expand Down
6 changes: 4 additions & 2 deletions src/PhpSpreadsheet/Worksheet/PageBreak.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class PageBreak

private int $maxColOrRow;

/** @param array|CellAddress|string $coordinate */
public function __construct(int $breakType, $coordinate, int $maxColOrRow = -1)
/**
* @param array{0: int, 1: int}|CellAddress|string $coordinate
*/
public function __construct(int $breakType, CellAddress|string|array $coordinate, int $maxColOrRow = -1)
{
$coordinate = Functions::trimSheetFromCellReference(Validations::validateCellAddress($coordinate));
$this->breakType = $breakType;
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 @@ -69,7 +69,7 @@ class Table implements Stringable
* or an AddressRange object.
* @param string $name (e.g. Table1)
*/
public function __construct($range = '', string $name = '')
public function __construct(AddressRange|string|array $range = '', string $name = '')
{
$this->style = new TableStyle();
$this->autoFilter = new AutoFilter($range);
Expand Down Expand Up @@ -272,7 +272,7 @@ public function getRange(): string
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
* or an AddressRange object.
*/
public function setRange($range = ''): self
public function setRange(AddressRange|string|array $range = ''): self
{
// extract coordinate
if ($range !== '') {
Expand Down
8 changes: 4 additions & 4 deletions src/PhpSpreadsheet/Worksheet/Validations.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class Validations
/**
* Validate a cell address.
*
* @param null|array<int>|CellAddress|string $cellAddress Coordinate of the cell as a string, eg: 'C5';
* @param null|array{0: int, 1: int}|CellAddress|string $cellAddress Coordinate of the cell as a string, eg: 'C5';
* or as an array of [$columnIndex, $row] (e.g. [3, 5]), or a CellAddress object.
*/
public static function validateCellAddress($cellAddress): string
public static function validateCellAddress(null|CellAddress|string|array $cellAddress): string
{
if (is_string($cellAddress)) {
[$worksheet, $address] = Worksheet::extractSheetTitle($cellAddress, true);
Expand All @@ -40,7 +40,7 @@ public static function validateCellAddress($cellAddress): string
* or as an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 12]),
* or as a CellAddress or AddressRange object.
*/
public static function validateCellOrCellRange($cellRange): string
public static function validateCellOrCellRange(AddressRange|CellAddress|int|string|array $cellRange): string
{
if (is_string($cellRange) || is_numeric($cellRange)) {
// Convert a single column reference like 'A' to 'A:A',
Expand All @@ -63,7 +63,7 @@ public static function validateCellOrCellRange($cellRange): string
* or as an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 12]),
* or as an AddressRange object.
*/
public static function validateCellRange(AddressRange|array|string $cellRange): string
public static function validateCellRange(AddressRange|string|array $cellRange): string
{
if (is_string($cellRange)) {
[$worksheet, $addressRange] = Worksheet::extractSheetTitle($cellRange, true);
Expand Down
Loading

0 comments on commit a83e9fb

Please sign in to comment.