Completed
Pull Request — master (#40)
by Mr
06:35
created

Wrapper::client()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace RouterOS\Laravel;
4
5
use RouterOS\Client;
6
use RouterOS\Config;
7
use RouterOS\Interfaces\ClientInterface;
8
use RouterOS\Interfaces\ConfigInterface;
9
10
class Wrapper
11
{
12
    /**
13
     * Alias for \RouterOS::client() method
14
     *
15
     * @param array $params
16
     *
17
     * @return \RouterOS\Client
18
     * @throws \RouterOS\Exceptions\ClientException
19
     * @throws \RouterOS\Exceptions\ConfigException
20
     * @throws \RouterOS\Exceptions\QueryException
21
     * @deprecated
22
     * @codeCoverageIgnore
23
     */
24
    public function getClient(array $params = []): ClientInterface
25
    {
26
        return $this->client($params);
27
    }
28
29
    /**
30
     * Get configs of library
31
     *
32
     * @param array $params
33
     *
34
     * @return \RouterOS\Interfaces\ConfigInterface
35
     * @throws \RouterOS\Exceptions\ConfigException
36
     */
37
    public function config(array $params = []): ConfigInterface
38
    {
39
        $config = config('routeros-api');
40
        $config = array_merge($config, $params);
41
        $config = new Config($config);
42
43
        return $config;
44
    }
45
46
    /**
47
     * Instantiate client object
48
     *
49
     * @param array $params
50
     * @param bool  $autoConnect
51
     *
52
     * @return \RouterOS\Interfaces\ClientInterface
53
     * @throws \RouterOS\Exceptions\ClientException
54
     * @throws \RouterOS\Exceptions\ConfigException
55
     * @throws \RouterOS\Exceptions\QueryException
56
     */
57
    public function client(array $params = [], bool $autoConnect = true): ClientInterface
58
    {
59
        $config = $this->config($params);
60
61
        return new Client($config, $autoConnect);
62
    }
63
}
64