From e75f6f73012b81fd5fee6107d0af9e86c458448e Mon Sep 17 00:00:00 2001 From: Adrien Loison Date: Thu, 13 Jan 2022 22:37:18 +0100 Subject: [PATCH] Fix PHP 8.1 deprecations --- .../Common/Helper/GlobalFunctionsHelper.php | 2 +- src/Spout/Reader/CSV/RowIterator.php | 16 ++++++++-------- src/Spout/Reader/CSV/SheetIterator.php | 16 ++++++++-------- src/Spout/Reader/ODS/RowIterator.php | 12 ++++++------ src/Spout/Reader/XLSX/RowIterator.php | 12 ++++++------ 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Spout/Common/Helper/GlobalFunctionsHelper.php b/src/Spout/Common/Helper/GlobalFunctionsHelper.php index 5deb8d9..c5c92bc 100644 --- a/src/Spout/Common/Helper/GlobalFunctionsHelper.php +++ b/src/Spout/Common/Helper/GlobalFunctionsHelper.php @@ -82,7 +82,7 @@ class GlobalFunctionsHelper * @param int|null $length * @param string|null $delimiter * @param string|null $enclosure - * @return array + * @return array|false */ public function fgetcsv($handle, $length = null, $delimiter = null, $enclosure = null) { diff --git a/src/Spout/Reader/CSV/RowIterator.php b/src/Spout/Reader/CSV/RowIterator.php index 1312d9c..233a14a 100644 --- a/src/Spout/Reader/CSV/RowIterator.php +++ b/src/Spout/Reader/CSV/RowIterator.php @@ -84,7 +84,7 @@ class RowIterator implements IteratorInterface * * @return void */ - public function rewind() + public function rewind() : void { $this->rewindAndSkipBom(); @@ -114,7 +114,7 @@ class RowIterator implements IteratorInterface * * @return bool */ - public function valid() + public function valid() : bool { return ($this->filePointer && !$this->hasReachedEndOfFile); } @@ -126,7 +126,7 @@ class RowIterator implements IteratorInterface * @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8 * @return void */ - public function next() + public function next() : void { $this->hasReachedEndOfFile = $this->globalFunctionsHelper->feof($this->filePointer); @@ -146,8 +146,8 @@ class RowIterator implements IteratorInterface } while ($this->shouldReadNextRow($rowData)); if ($rowData !== false) { - // str_replace will replace NULL values by empty strings - $rowDataBufferAsArray = \str_replace(null, null, $rowData); + // array_map will replace NULL values by empty strings + $rowDataBufferAsArray = array_map(function ($value) { return (string) $value; }, $rowData); $this->rowBuffer = $this->entityFactory->createRowFromArray($rowDataBufferAsArray); $this->numReadRows++; } else { @@ -224,7 +224,7 @@ class RowIterator implements IteratorInterface * * @return Row|null */ - public function current() + public function current() : ?Row { return $this->rowBuffer; } @@ -235,7 +235,7 @@ class RowIterator implements IteratorInterface * * @return int */ - public function key() + public function key() : int { return $this->numReadRows; } @@ -245,7 +245,7 @@ class RowIterator implements IteratorInterface * * @return void */ - public function end() + public function end() : void { // do nothing } diff --git a/src/Spout/Reader/CSV/SheetIterator.php b/src/Spout/Reader/CSV/SheetIterator.php index 69eb58a..84c3c80 100644 --- a/src/Spout/Reader/CSV/SheetIterator.php +++ b/src/Spout/Reader/CSV/SheetIterator.php @@ -10,7 +10,7 @@ use Box\Spout\Reader\IteratorInterface; */ class SheetIterator implements IteratorInterface { - /** @var \Box\Spout\Reader\CSV\Sheet The CSV unique "sheet" */ + /** @var Sheet The CSV unique "sheet" */ protected $sheet; /** @var bool Whether the unique "sheet" has already been read */ @@ -30,7 +30,7 @@ class SheetIterator implements IteratorInterface * * @return void */ - public function rewind() + public function rewind() : void { $this->hasReadUniqueSheet = false; } @@ -41,7 +41,7 @@ class SheetIterator implements IteratorInterface * * @return bool */ - public function valid() + public function valid() : bool { return (!$this->hasReadUniqueSheet); } @@ -52,7 +52,7 @@ class SheetIterator implements IteratorInterface * * @return void */ - public function next() + public function next() : void { $this->hasReadUniqueSheet = true; } @@ -61,9 +61,9 @@ class SheetIterator implements IteratorInterface * Return the current element * @see http://php.net/manual/en/iterator.current.php * - * @return \Box\Spout\Reader\CSV\Sheet + * @return Sheet */ - public function current() + public function current() : Sheet { return $this->sheet; } @@ -74,7 +74,7 @@ class SheetIterator implements IteratorInterface * * @return int */ - public function key() + public function key() : int { return 1; } @@ -84,7 +84,7 @@ class SheetIterator implements IteratorInterface * * @return void */ - public function end() + public function end() : void { // do nothing } diff --git a/src/Spout/Reader/ODS/RowIterator.php b/src/Spout/Reader/ODS/RowIterator.php index b804376..29643b7 100644 --- a/src/Spout/Reader/ODS/RowIterator.php +++ b/src/Spout/Reader/ODS/RowIterator.php @@ -118,7 +118,7 @@ class RowIterator implements IteratorInterface * @throws \Box\Spout\Reader\Exception\IteratorNotRewindableException If the iterator is rewound more than once * @return void */ - public function rewind() + public function rewind() : void { // Because sheet and row data is located in the file, we can't rewind both the // sheet iterator and the row iterator, as XML file cannot be read backwards. @@ -142,7 +142,7 @@ class RowIterator implements IteratorInterface * * @return bool */ - public function valid() + public function valid() : bool { return (!$this->hasReachedEndOfFile); } @@ -155,7 +155,7 @@ class RowIterator implements IteratorInterface * @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML * @return void */ - public function next() + public function next() : void { if ($this->doesNeedDataForNextRowToBeProcessed()) { $this->readDataForNextRow(); @@ -356,7 +356,7 @@ class RowIterator implements IteratorInterface * * @return Row */ - public function current() + public function current() : Row { return $this->rowBuffer; } @@ -367,7 +367,7 @@ class RowIterator implements IteratorInterface * * @return int */ - public function key() + public function key() : int { return $this->lastRowIndexProcessed; } @@ -377,7 +377,7 @@ class RowIterator implements IteratorInterface * * @return void */ - public function end() + public function end() : void { $this->xmlReader->close(); } diff --git a/src/Spout/Reader/XLSX/RowIterator.php b/src/Spout/Reader/XLSX/RowIterator.php index e9cafdd..93c2b9d 100644 --- a/src/Spout/Reader/XLSX/RowIterator.php +++ b/src/Spout/Reader/XLSX/RowIterator.php @@ -139,7 +139,7 @@ class RowIterator implements IteratorInterface * @throws \Box\Spout\Common\Exception\IOException If the sheet data XML cannot be read * @return void */ - public function rewind() + public function rewind() : void { $this->xmlReader->close(); @@ -163,7 +163,7 @@ class RowIterator implements IteratorInterface * * @return bool */ - public function valid() + public function valid() : bool { return (!$this->hasReachedEndOfFile); } @@ -176,7 +176,7 @@ class RowIterator implements IteratorInterface * @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML * @return void */ - public function next() + public function next() : void { $this->nextRowIndexToBeProcessed++; @@ -374,7 +374,7 @@ class RowIterator implements IteratorInterface * * @return Row|null */ - public function current() + public function current() : ?Row { $rowToBeProcessed = $this->rowBuffer; @@ -399,7 +399,7 @@ class RowIterator implements IteratorInterface * * @return int */ - public function key() + public function key() : int { // TODO: This should return $this->nextRowIndexToBeProcessed // but to avoid a breaking change, the return value for @@ -414,7 +414,7 @@ class RowIterator implements IteratorInterface * * @return void */ - public function end() + public function end() : void { $this->xmlReader->close(); }