diff --git a/src/ControlClient.php b/src/ControlClient.php index 6a8754f..da727a8 100644 --- a/src/ControlClient.php +++ b/src/ControlClient.php @@ -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()); } diff --git a/src/ProtocolReply.php b/src/ProtocolReply.php index 918b23a..0d6abff 100644 --- a/src/ProtocolReply.php +++ b/src/ProtocolReply.php @@ -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; @@ -195,7 +196,7 @@ public function isPositiveReply() } } - public function shift(): mixed + public function shift() { $this->dirty = true; return array_shift($this->lines); @@ -205,7 +206,7 @@ public function shift(): mixed * (non-PHPdoc) * @see Iterator::rewind() */ - public function rewind() + public function rewind(): void { $this->position = 0; } @@ -241,7 +242,7 @@ public function key() * (non-PHPdoc) * @see Iterator::next() */ - public function next() + public function next(): void { ++$this->position; } @@ -250,7 +251,7 @@ public function next() * (non-PHPdoc) * @see Iterator::valid() */ - public function valid() + public function valid(): bool { return ($this->key() !== null); } @@ -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]); } @@ -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; @@ -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); }