Browse Source

small tunes of code, migration to php 7.2

tags/1.2.0
Paul Rock 6 years ago
parent
commit
e929d6d67a
  1. 9
      src/Config.php
  2. 14
      src/Interfaces/ClientInterface.php
  3. 9
      src/Interfaces/ConfigInterface.php
  4. 6
      src/Interfaces/QueryInterface.php
  5. 6
      src/Interfaces/StreamInterface.php
  6. 7
      src/Laravel/ClientFacade.php
  7. 4
      src/Laravel/ClientServiceProvide.php
  8. 3
      src/ResponseIterator.php

9
src/Config.php

@ -32,7 +32,8 @@ class Config implements ConfigInterface
* Config constructor. * Config constructor.
* *
* @param array $parameters List of parameters which can be set on object creation stage * @param array $parameters List of parameters which can be set on object creation stage
* @throws ConfigException
*
* @throws \RouterOS\Exceptions\ConfigException
* @since 0.6 * @since 0.6
*/ */
public function __construct(array $parameters = []) public function __construct(array $parameters = [])
@ -47,8 +48,9 @@ class Config implements ConfigInterface
* *
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
*
* @return \RouterOS\Config * @return \RouterOS\Config
* @throws ConfigException
* @throws \RouterOS\Exceptions\ConfigException
*/ */
public function set(string $name, $value): Config public function set(string $name, $value): Config
{ {
@ -72,6 +74,7 @@ class Config implements ConfigInterface
* Return port number (get from defaults if port is not set by user) * Return port number (get from defaults if port is not set by user)
* *
* @param string $parameter * @param string $parameter
*
* @return bool|int * @return bool|int
*/ */
private function getPort(string $parameter) private function getPort(string $parameter)
@ -90,6 +93,7 @@ class Config implements ConfigInterface
* Remove parameter from array by name * Remove parameter from array by name
* *
* @param string $name * @param string $name
*
* @return \RouterOS\Config * @return \RouterOS\Config
* @throws \RouterOS\Exceptions\ConfigException * @throws \RouterOS\Exceptions\ConfigException
*/ */
@ -110,6 +114,7 @@ class Config implements ConfigInterface
* Return parameter of current config by name * Return parameter of current config by name
* *
* @param string $name * @param string $name
*
* @return mixed * @return mixed
* @throws \RouterOS\Exceptions\ConfigException * @throws \RouterOS\Exceptions\ConfigException
*/ */

14
src/Interfaces/ClientInterface.php

@ -16,37 +16,37 @@ interface ClientInterface
/** /**
* By default legacy login on RouterOS pre-6.43 is not supported * By default legacy login on RouterOS pre-6.43 is not supported
*/ */
const LEGACY = false;
public const LEGACY = false;
/** /**
* Default port number * Default port number
*/ */
const PORT = 8728;
public const PORT = 8728;
/** /**
* Default ssl port number * Default ssl port number
*/ */
const PORT_SSL = 8729;
public const PORT_SSL = 8729;
/** /**
* Do not use SSL by default * Do not use SSL by default
*/ */
const SSL = false;
public const SSL = false;
/** /**
* Max timeout for answer from router * Max timeout for answer from router
*/ */
const TIMEOUT = 10;
public const TIMEOUT = 10;
/** /**
* Count of reconnect attempts * Count of reconnect attempts
*/ */
const ATTEMPTS = 10;
public const ATTEMPTS = 10;
/** /**
* Delay between attempts in seconds * Delay between attempts in seconds
*/ */
const ATTEMPTS_DELAY = 1;
public const ATTEMPTS_DELAY = 1;
/** /**
* Return socket resource if is exist * Return socket resource if is exist

9
src/Interfaces/ConfigInterface.php

@ -15,7 +15,7 @@ interface ConfigInterface
/** /**
* List of allowed parameters of config * List of allowed parameters of config
*/ */
const ALLOWED = [
public const ALLOWED = [
// Address of Mikrotik RouterOS // Address of Mikrotik RouterOS
'host' => 'string', 'host' => 'string',
// Username // Username
@ -41,7 +41,8 @@ interface ConfigInterface
* *
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
* @return Config
*
* @return \RouterOS\Config
*/ */
public function set(string $name, $value): Config; public function set(string $name, $value): Config;
@ -49,7 +50,8 @@ interface ConfigInterface
* Remove parameter from array by name * Remove parameter from array by name
* *
* @param string $parameter * @param string $parameter
* @return Config
*
* @return \RouterOS\Config
*/ */
public function delete(string $parameter): Config; public function delete(string $parameter): Config;
@ -57,6 +59,7 @@ interface ConfigInterface
* Return parameter of current config by name * Return parameter of current config by name
* *
* @param string $parameter * @param string $parameter
*
* @return mixed * @return mixed
*/ */
public function get(string $parameter); public function get(string $parameter);

6
src/Interfaces/QueryInterface.php

@ -18,6 +18,7 @@ interface QueryInterface
* @param string $key Key which need to find * @param string $key Key which need to find
* @param bool|string|int $value Value which need to check (by default true) * @param bool|string|int $value Value which need to check (by default true)
* @param bool|string|int $operator It may be one from list [-,=,>,<] * @param bool|string|int $operator It may be one from list [-,=,>,<]
*
* @return \RouterOS\Query * @return \RouterOS\Query
* @throws \RouterOS\Exceptions\ClientException * @throws \RouterOS\Exceptions\ClientException
* @since 1.0.0 * @since 1.0.0
@ -28,6 +29,7 @@ interface QueryInterface
* Append additional operations * Append additional operations
* *
* @param string $operations * @param string $operations
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function operations(string $operations); public function operations(string $operations);
@ -36,6 +38,7 @@ interface QueryInterface
* Append tag to query (it should be at end) * Append tag to query (it should be at end)
* *
* @param string $name * @param string $name
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function tag(string $name); public function tag(string $name);
@ -44,6 +47,7 @@ interface QueryInterface
* Append to array yet another attribute of query * Append to array yet another attribute of query
* *
* @param string $word * @param string $word
*
* @return \RouterOS\Query * @return \RouterOS\Query
*/ */
public function add(string $word): Query; public function add(string $word): Query;
@ -59,6 +63,7 @@ interface QueryInterface
* Set array of attributes * Set array of attributes
* *
* @param array $attributes * @param array $attributes
*
* @return \RouterOS\Query * @return \RouterOS\Query
* @since 0.7 * @since 0.7
*/ */
@ -75,6 +80,7 @@ interface QueryInterface
* Set endpoint of query * Set endpoint of query
* *
* @param string $endpoint * @param string $endpoint
*
* @return \RouterOS\Query * @return \RouterOS\Query
* @since 0.7 * @since 0.7
*/ */

6
src/Interfaces/StreamInterface.php

@ -18,7 +18,8 @@ interface StreamInterface
* Reads $length bytes from the stream, returns the bytes into a string * Reads $length bytes from the stream, returns the bytes into a string
* Must be binary safe (as fread). * Must be binary safe (as fread).
* *
* @param int $length the numer of bytes to read
* @param int $length the number of bytes to read
*
* @return string a binary string containing the readed byes * @return string a binary string containing the readed byes
*/ */
public function read(int $length): string; public function read(int $length): string;
@ -33,6 +34,7 @@ interface StreamInterface
* *
* @param string $string * @param string $string
* @param int $length the number of bytes to read * @param int $length the number of bytes to read
*
* @return int return number of written bytes * @return int return number of written bytes
*/ */
public function write(string $string, int $length = -1): int; public function write(string $string, int $length = -1): int;
@ -42,5 +44,5 @@ interface StreamInterface
* *
* @return void * @return void
*/ */
public function close();
public function close(): void;
} }

7
src/Laravel/ClientFacade.php

@ -6,7 +6,12 @@ use Illuminate\Support\Facades\Facade;
class ClientFacade extends Facade class ClientFacade extends Facade
{ {
protected static function getFacadeAccessor()
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{ {
return ClientWrapper::class; return ClientWrapper::class;
} }

4
src/Laravel/ClientServiceProvide.php

@ -11,7 +11,7 @@ class ClientServiceProvide extends BaseServiceProvider
* *
* @return void * @return void
*/ */
public function boot()
public function boot(): void
{ {
$this->publishes([ $this->publishes([
__DIR__ . '/../../configs/routeros-api.php' => config_path('routeros-api.php'), __DIR__ . '/../../configs/routeros-api.php' => config_path('routeros-api.php'),
@ -23,7 +23,7 @@ class ClientServiceProvide extends BaseServiceProvider
* *
* @return void * @return void
*/ */
public function register()
public function register(): void
{ {
$this->mergeConfigFrom( $this->mergeConfigFrom(
__DIR__ . '/../../configs/routeros-api.php', 'routeros-api' __DIR__ . '/../../configs/routeros-api.php', 'routeros-api'

3
src/ResponseIterator.php

@ -12,6 +12,7 @@ use \Iterator,
* from RouterOS to readable array in safe way. * from RouterOS to readable array in safe way.
* *
* @param array $raw Array RAW response from server * @param array $raw Array RAW response from server
*
* @return mixed * @return mixed
* *
* Based on RouterOSResponseArray solution by @arily * Based on RouterOSResponseArray solution by @arily
@ -188,6 +189,7 @@ class ResponseIterator implements Iterator, ArrayAccess, Countable, Serializable
* Whether a offset exists * Whether a offset exists
* *
* @param mixed $offset * @param mixed $offset
*
* @return bool * @return bool
*/ */
public function offsetExists($offset): bool public function offsetExists($offset): bool
@ -209,6 +211,7 @@ class ResponseIterator implements Iterator, ArrayAccess, Countable, Serializable
* Offset to retrieve * Offset to retrieve
* *
* @param mixed $offset * @param mixed $offset
*
* @return bool|mixed * @return bool|mixed
*/ */
public function offsetGet($offset) public function offsetGet($offset)

Loading…
Cancel
Save