Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to php8 #181

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions SpreadsheetReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct($Filepath, $OriginalFilename = false, $MimeType = fa
{
throw new Exception('SpreadsheetReader: File ('.$Filepath.') not readable');
}

// To avoid timezone warnings and exceptions for formatting dates retrieved from files
$DefaultTZ = @date_default_timezone_get();
if ($DefaultTZ)
Expand All @@ -70,7 +70,7 @@ public function __construct($Filepath, $OriginalFilename = false, $MimeType = fa
}

$Extension = strtolower(pathinfo($OriginalFilename, PATHINFO_EXTENSION));

switch ($MimeType)
{
case 'text/csv':
Expand Down Expand Up @@ -230,7 +230,7 @@ private static function Load($Type)
* Rewind the Iterator to the first element.
* Similar to the reset() function for arrays in PHP
*/
public function rewind()
public function rewind(): void
{
$this -> Index = 0;
if ($this -> Handle)
Expand All @@ -245,7 +245,7 @@ public function rewind()
*
* @return mixed current element from the collection
*/
public function current()
public function current(): mixed
{
if ($this -> Handle)
{
Expand All @@ -258,15 +258,15 @@ public function current()
* Move forward to next element.
* Similar to the next() function for arrays in PHP
*/
public function next()
public function next(): void
{
if ($this -> Handle)
{
$this -> Index++;

return $this -> Handle -> next();
$this -> Handle -> next();
}
return null;
//return null;
}

/**
Expand All @@ -275,7 +275,7 @@ public function next()
*
* @return mixed either an integer or a string
*/
public function key()
public function key(): mixed
{
if ($this -> Handle)
{
Expand All @@ -290,7 +290,7 @@ public function key()
*
* @return boolean FALSE if there's nothing more to iterate over
*/
public function valid()
public function valid(): bool
{
if ($this -> Handle)
{
Expand All @@ -300,7 +300,7 @@ public function valid()
}

// !Countable interface method
public function count()
public function count(): int
{
if ($this -> Handle)
{
Expand All @@ -315,13 +315,17 @@ public function count()
*
* @param int Position in file
*/
public function seek($Position)
public function seek($Position): void
{
if (!$this -> Handle)
{
throw new OutOfBoundsException('SpreadsheetReader: No file opened');
}

if (!isset($this ->Handle[$position])) {
throw new OutOfBoundsException("invalid seek position ($position)");
}

$CurrentIndex = $this -> Handle -> key();

if ($CurrentIndex != $Position)
Expand All @@ -342,7 +346,7 @@ public function seek($Position)
}
}

return null;
//return null;
}
}
?>
16 changes: 8 additions & 8 deletions SpreadsheetReader_CSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function ChangeSheet($Index)
* Rewind the Iterator to the first element.
* Similar to the reset() function for arrays in PHP
*/
public function rewind()
public function rewind(): void
{
fseek($this -> Handle, $this -> BOMLength);
$this -> CurrentRow = null;
Expand All @@ -169,7 +169,7 @@ public function rewind()
*
* @return mixed current element from the collection
*/
public function current()
public function current(): mixed
{
if ($this -> Index == 0 && is_null($this -> CurrentRow))
{
Expand All @@ -183,7 +183,7 @@ public function current()
* Move forward to next element.
* Similar to the next() function for arrays in PHP
*/
public function next()
public function next(): void
{
$this -> CurrentRow = array();

Expand Down Expand Up @@ -239,7 +239,7 @@ public function next()
}
}

return $this -> CurrentRow;
//return $this -> CurrentRow;
}

/**
Expand All @@ -248,7 +248,7 @@ public function next()
*
* @return mixed either an integer or a string
*/
public function key()
public function key(): mixed
{
return $this -> Index;
}
Expand All @@ -259,7 +259,7 @@ public function key()
*
* @return boolean FALSE if there's nothing more to iterate over
*/
public function valid()
public function valid(): bool
{
return ($this -> CurrentRow || !feof($this -> Handle));
}
Expand All @@ -269,9 +269,9 @@ public function valid()
* Ostensibly should return the count of the contained items but this just returns the number
* of rows read so far. It's not really correct but at least coherent.
*/
public function count()
public function count(): int
{
return $this -> Index + 1;
}
}
?>
?>
16 changes: 8 additions & 8 deletions SpreadsheetReader_ODS.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function ChangeSheet($Index)
* Rewind the Iterator to the first element.
* Similar to the reset() function for arrays in PHP
*/
public function rewind()
public function rewind(): void
{
if ($this -> Index > 0)
{
Expand All @@ -182,7 +182,7 @@ public function rewind()
*
* @return mixed current element from the collection
*/
public function current()
public function current(): mixed
{
if ($this -> Index == 0 && is_null($this -> CurrentRow))
{
Expand All @@ -196,7 +196,7 @@ public function current()
* Move forward to next element.
* Similar to the next() function for arrays in PHP
*/
public function next()
public function next(): void
{
$this -> Index++;

Expand Down Expand Up @@ -301,7 +301,7 @@ public function next()
}
}

return $this -> CurrentRow;
//return $this -> CurrentRow;
}

/**
Expand All @@ -310,7 +310,7 @@ public function next()
*
* @return mixed either an integer or a string
*/
public function key()
public function key(): mixed
{
return $this -> Index;
}
Expand All @@ -321,7 +321,7 @@ public function key()
*
* @return boolean FALSE if there's nothing more to iterate over
*/
public function valid()
public function valid(): bool
{
return $this -> Valid;
}
Expand All @@ -331,9 +331,9 @@ public function valid()
* Ostensibly should return the count of the contained items but this just returns the number
* of rows read so far. It's not really correct but at least coherent.
*/
public function count()
public function count(): int
{
return $this -> Index + 1;
}
}
?>
?>
34 changes: 18 additions & 16 deletions SpreadsheetReader_XLS.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function __get($Name)
* Rewind the Iterator to the first element.
* Similar to the reset() function for arrays in PHP
*/
public function rewind()
public function rewind(): void
{
$this -> Index = 0;
}
Expand All @@ -176,7 +176,7 @@ public function rewind()
*
* @return mixed current element from the collection
*/
public function current()
public function current(): mixed
{
if ($this -> Index == 0)
{
Expand All @@ -190,35 +190,37 @@ public function current()
* Move forward to next element.
* Similar to the next() function for arrays in PHP
*/
public function next()
public function next(): void
{
// Internal counter is advanced here instead of the if statement
// because apparently it's fully possible that an empty row will not be
// present at all
$this -> Index++;

$this -> CurrentRow = array();

if ($this -> Error)
{
return array();
//return array();
}
elseif (isset($this -> Handle -> sheets[$this -> CurrentSheet]['cells'][$this -> Index]))
{
$this -> CurrentRow = $this -> Handle -> sheets[$this -> CurrentSheet]['cells'][$this -> Index];
if (!$this -> CurrentRow)
if ($this -> CurrentRow)
{
return array();
}
$this -> CurrentRow = $this -> CurrentRow + $this -> EmptyRow;
ksort($this -> CurrentRow);

$this -> CurrentRow = $this -> CurrentRow + $this -> EmptyRow;
ksort($this -> CurrentRow);
$this -> CurrentRow = array_values($this -> CurrentRow);
//return $this -> CurrentRow;
}
//return array();

$this -> CurrentRow = array_values($this -> CurrentRow);
return $this -> CurrentRow;
}
else
{
$this -> CurrentRow = $this -> EmptyRow;
return $this -> CurrentRow;
//return $this -> CurrentRow;
}
}

Expand All @@ -228,7 +230,7 @@ public function next()
*
* @return mixed either an integer or a string
*/
public function key()
public function key(): mixed
{
return $this -> Index;
}
Expand All @@ -239,7 +241,7 @@ public function key()
*
* @return boolean FALSE if there's nothing more to iterate over
*/
public function valid()
public function valid(): bool
{
if ($this -> Error)
{
Expand All @@ -253,7 +255,7 @@ public function valid()
* Ostensibly should return the count of the contained items but this just returns the number
* of rows read so far. It's not really correct but at least coherent.
*/
public function count()
public function count(): int
{
if ($this -> Error)
{
Expand All @@ -263,4 +265,4 @@ public function count()
return $this -> RowCount;
}
}
?>
?>
Loading