type fixes

This commit is contained in:
Robin Appelman 2021-03-02 20:56:24 +01:00
commit b69c20d21a
12 changed files with 25 additions and 19 deletions

View file

@ -42,6 +42,9 @@ class Connection extends RawConnection {
$this->write('');
do {
$promptLine = $this->readLine();
if ($promptLine === false) {
break;
}
$this->parser->checkConnectionError($promptLine);
} while (!$this->isPrompt($promptLine));
if ($this->write('') === false) {
@ -66,6 +69,9 @@ class Connection extends RawConnection {
throw new ConnectionException('Connection not valid');
}
$promptLine = $this->readLine(); //first line is prompt
if ($promptLine === false) {
$this->unknownError($promptLine);
}
$this->parser->checkConnectionError($promptLine);
$output = [];
@ -77,7 +83,7 @@ class Connection extends RawConnection {
if ($line === false) {
$this->unknownError($promptLine);
}
while (!$this->isPrompt($line)) { //next prompt functions as delimiter
while ($line !== false && !$this->isPrompt($line)) { //next prompt functions as delimiter
if (is_callable($callback)) {
$result = $callback($line);
if ($result === false) { // allow the callback to close the connection for infinite running commands
@ -99,11 +105,11 @@ class Connection extends RawConnection {
* @return bool
*/
private function isPrompt(string $line) {
return mb_substr($line, 0, self::DELIMITER_LENGTH) === self::DELIMITER || $line === false;
return mb_substr($line, 0, self::DELIMITER_LENGTH) === self::DELIMITER;
}
/**
* @param string $promptLine (optional) prompt line that might contain some info about the error
* @param string|bool $promptLine (optional) prompt line that might contain some info about the error
* @throws ConnectException
*/
private function unknownError($promptLine = '') {