mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-30 12:07:56 +00:00
Remove all mixed in param type where reasonable (except Calculcation/)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -34,18 +34,18 @@ class CellAddress implements Stringable
|
||||
* @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
|
||||
@@ -55,7 +55,7 @@ class CellAddress implements Stringable
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -67,7 +67,7 @@ class StringValueBinder 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
|
||||
{
|
||||
if (is_object($value)) {
|
||||
return $this->bindObjectValue($cell, $value);
|
||||
|
||||
@@ -112,9 +112,9 @@ class Axis extends Properties
|
||||
/**
|
||||
* 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)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -232,7 +232,7 @@ class DataSeries
|
||||
*
|
||||
* @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)) {
|
||||
@@ -257,7 +257,7 @@ class DataSeries
|
||||
*
|
||||
* @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)) {
|
||||
@@ -304,7 +304,7 @@ class DataSeries
|
||||
*
|
||||
* @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)) {
|
||||
|
||||
@@ -88,7 +88,7 @@ class PlotArea
|
||||
/**
|
||||
* Get Plot Series by Index.
|
||||
*/
|
||||
public function getPlotGroupByIndex(mixed $index): DataSeries
|
||||
public function getPlotGroupByIndex(int $index): DataSeries
|
||||
{
|
||||
return $this->plotSeries[$index];
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@ abstract class Properties
|
||||
/**
|
||||
* 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)) {
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -998,7 +998,7 @@ class Html extends BaseReader
|
||||
/**
|
||||
* 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, '#')) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,8 @@ class Chart
|
||||
$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();
|
||||
@@ -381,7 +382,7 @@ class Chart
|
||||
|
||||
break;
|
||||
case 'plotVisOnly':
|
||||
$plotVisOnly = self::getAttributeString($chartDetails, 'val');
|
||||
$plotVisOnly = (bool) self::getAttributeString($chartDetails, 'val');
|
||||
|
||||
break;
|
||||
case 'dispBlanksAs':
|
||||
|
||||
@@ -429,8 +429,8 @@ class Styles extends BaseParserClass
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class WorkbookView
|
||||
$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);
|
||||
|
||||
@@ -195,7 +195,7 @@ class Date
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -175,7 +175,7 @@ class PPS
|
||||
*
|
||||
* @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;
|
||||
|
||||
@@ -287,10 +287,10 @@ class Spreadsheet implements JsonSerializable
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
@@ -318,16 +318,6 @@ class Spreadsheet implements JsonSerializable
|
||||
$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.
|
||||
*/
|
||||
@@ -351,7 +341,7 @@ class Spreadsheet implements JsonSerializable
|
||||
&& 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
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ class Settings extends WriterPart
|
||||
|
||||
private function writeFreezePane(XMLWriter $objWriter, Worksheet $worksheet): void
|
||||
{
|
||||
$freezePane = CellAddress::fromCellAddress($worksheet->getFreezePane());
|
||||
$freezePane = CellAddress::fromCellAddress($worksheet->getFreezePane() ?? '');
|
||||
if ($freezePane->cellAddress() === 'A1') {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,10 +16,8 @@ class Escher
|
||||
{
|
||||
/**
|
||||
* The object we are writing.
|
||||
*
|
||||
* @var Blip|BSE|BstoreContainer|DgContainer|DggContainer|Escher|SpContainer|SpgrContainer
|
||||
*/
|
||||
private $object;
|
||||
private Blip|BSE|BstoreContainer|DgContainer|DggContainer|Escher|SpContainer|SpgrContainer|SharedEscher $object;
|
||||
|
||||
/**
|
||||
* The written binary data.
|
||||
@@ -39,7 +37,7 @@ class Escher
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct(mixed $object)
|
||||
public function __construct(Blip|BSE|BstoreContainer|DgContainer|DggContainer|self|SpContainer|SpgrContainer|SharedEscher $object)
|
||||
{
|
||||
$this->object = $object;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class Chart extends WriterPart
|
||||
*
|
||||
* @return string XML Output
|
||||
*/
|
||||
public function writeChart(\PhpOffice\PhpSpreadsheet\Chart\Chart $chart, mixed $calculateCellValues = true): string
|
||||
public function writeChart(\PhpOffice\PhpSpreadsheet\Chart\Chart $chart, bool $calculateCellValues = true): string
|
||||
{
|
||||
// Create XML writer
|
||||
$objWriter = null;
|
||||
|
||||
@@ -41,7 +41,7 @@ class CellAddressTest extends TestCase
|
||||
/**
|
||||
* @dataProvider providerCreateFromCellAddressException
|
||||
*/
|
||||
public function testCreateFromCellAddressException(int|string $cellAddress): void
|
||||
public function testCreateFromCellAddressException(string $cellAddress): void
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage(
|
||||
@@ -60,7 +60,6 @@ class CellAddressTest extends TestCase
|
||||
[''],
|
||||
['IV'],
|
||||
['12'],
|
||||
[123],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user