Browse Source

couple bugs fixed in Client class

pull/33/head
Paul Rock 6 years ago
parent
commit
17522170e2
  1. 21
      src/Client.php

21
src/Client.php

@ -7,6 +7,7 @@ use RouterOS\Exceptions\ConfigException;
use RouterOS\Exceptions\QueryException; use RouterOS\Exceptions\QueryException;
use RouterOS\Helpers\ArrayHelper; use RouterOS\Helpers\ArrayHelper;
use RouterOS\Interfaces\QueryInterface;
use function array_keys; use function array_keys;
use function array_shift; use function array_shift;
use function chr; use function chr;
@ -90,7 +91,7 @@ class Client implements Interfaces\ClientInterface
/** /**
* Send write query to RouterOS * Send write query to RouterOS
* *
* @param string|array|Query $query
* @param string|array|\RouterOS\Query $query
* *
* @return \RouterOS\Client * @return \RouterOS\Client
* @throws \RouterOS\Exceptions\QueryException * @throws \RouterOS\Exceptions\QueryException
@ -164,8 +165,8 @@ class Client implements Interfaces\ClientInterface
/** /**
* Query helper * Query helper
* *
* @param array $item
* @param Query $query
* @param array $item
* @param \RouterOS\Interfaces\QueryInterface $query
* *
* @return \RouterOS\Query * @return \RouterOS\Query
* @throws \RouterOS\Exceptions\ClientException * @throws \RouterOS\Exceptions\ClientException
@ -364,12 +365,12 @@ class Client implements Interfaces\ClientInterface
for ($j = $key + 1; $j <= $lines; $j++) { for ($j = $key + 1; $j <= $lines; $j++) {
// If we have lines after current one // If we have lines after current one
if (isset($response[$j])) { if (isset($response[$j])) {
$this->preParseResponse($response[$j], $result, $matches, $j);
$this->preParseResponse($response[$j], $result, $matches);
} }
} }
break 2; break 2;
default: default:
$this->preParseResponse($value, $result, $matches);
$this->preParseResponse($value, $result, $matches, $i);
break; break;
} }
} }
@ -381,10 +382,10 @@ class Client implements Interfaces\ClientInterface
* *
* @param string $value Value which should be parsed * @param string $value Value which should be parsed
* @param array $result Array with parsed response * @param array $result Array with parsed response
* @param array $matches Matched words
* @param null|array $matches Matched words
* @param string|int $iterator Type of iterations or number of item * @param string|int $iterator Type of iterations or number of item
*/ */
private function preParseResponse(string $value, array &$result, array &$matches, $iterator = 'after'): void
private function preParseResponse(string $value, array &$result, ?array &$matches, $iterator = 'after'): void
{ {
$this->pregResponse($value, $matches); $this->pregResponse($value, $matches);
if (isset($matches[1][0], $matches[2][0])) { if (isset($matches[1][0], $matches[2][0])) {
@ -395,10 +396,10 @@ class Client implements Interfaces\ClientInterface
/** /**
* Parse result from RouterOS by regular expression * Parse result from RouterOS by regular expression
* *
* @param string $value
* @param array $matches
* @param string $value
* @param null|array $matches
*/ */
private function pregResponse(string $value, array &$matches): void
private function pregResponse(string $value, ?array &$matches): void
{ {
preg_match_all('/^[=|.](.*)=(.*)/', $value, $matches); preg_match_all('/^[=|.](.*)=(.*)/', $value, $matches);
} }

Loading…
Cancel
Save