Skip to content

Commit

Permalink
PHP 8 compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dapphp committed Feb 15, 2022
1 parent f23d5ae commit 1dbbd82
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/ControlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,9 @@ private function authenticatePassword($password = null)
$reply = $this->readReply($cmd);

if (!$reply->isPositiveReply()) {
@fclose($this->sock); // failed auth closes connection
if ($this->sock) {
@fclose($this->sock); // failed auth closes connection
}
throw new ProtocolError($reply[0], $reply->getStatusCode());
}

Expand Down
21 changes: 11 additions & 10 deletions src/ProtocolReply.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,16 @@ public function appendReplyLine($line)
$status = null;
$first = sizeof($this->lines) == 0;
$line = rtrim($line, "\r\n");
$command = !empty($this->command) ? $this->command : '';

if (preg_match('/^(\d{3})-' . preg_quote($this->command, '/') . '=(.*)$/', $line, $match)) {
if (preg_match('/^(\d{3})-' . preg_quote($command, '/') . '=(.*)$/', $line, $match)) {
// ###-COMMAND=data reply...
$status = $match[1];

if (strlen(trim($match[2])) > 0) {
$this->lines[]= $match[2];
}
} elseif ($first && preg_match('/^(\d{3})\+' . preg_quote($this->command, '/') . '=$/', $line, $match)) {
} elseif ($first && preg_match('/^(\d{3})\+' . preg_quote($command, '/') . '=$/', $line, $match)) {
// ###+COMMAND=
$status = $match[1];
$this->dataReply = true;
Expand Down Expand Up @@ -195,7 +196,7 @@ public function isPositiveReply()
}
}

public function shift(): mixed
public function shift()
{
$this->dirty = true;
return array_shift($this->lines);
Expand All @@ -205,7 +206,7 @@ public function shift(): mixed
* (non-PHPdoc)
* @see Iterator::rewind()
*/
public function rewind()
public function rewind(): void
{
$this->position = 0;
}
Expand Down Expand Up @@ -241,7 +242,7 @@ public function key()
* (non-PHPdoc)
* @see Iterator::next()
*/
public function next()
public function next(): void
{
++$this->position;
}
Expand All @@ -250,7 +251,7 @@ public function next()
* (non-PHPdoc)
* @see Iterator::valid()
*/
public function valid()
public function valid(): bool
{
return ($this->key() !== null);
}
Expand All @@ -261,7 +262,7 @@ public function valid()
* @return bool
* @see ArrayAccess::offsetExists()
*/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return isset($this->lines[$offset]);
}
Expand All @@ -283,7 +284,7 @@ public function offsetGet($offset)
* @param $value
* @see ArrayAccess::offsetSet()
*/
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
if (is_null($offset)) {
$this->lines[] = $value;
Expand All @@ -298,13 +299,13 @@ public function offsetSet($offset, $value)
* @param $offset
* @see ArrayAccess::offsetUnset()
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->lines[$offset]);
$this->dirty = true;
}

public function count()
public function count(): int
{
return count($this->lines);
}
Expand Down

0 comments on commit 1dbbd82

Please sign in to comment.