Dynamark3Client   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 63
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A connect() 0 9 1
A __call() 0 10 1
A factory() 0 7 1
1
<?php
2
3
/**
4
 * This file is part of graze/dynamark3-client.
5
 *
6
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://github.com/graze/dynamark3-client/blob/master/LICENSE.md
12
 * @link    https://github.com/graze/dynamark3-client
13
 */
14
15
namespace Graze\Dynamark3Client;
16
17
use \Graze\TelnetClient\TelnetClientInterface;
18
use \Graze\Dynamark3Client\CommandResolver;
19
use \Graze\Dynamark3Client\Command\CommandInterface;
20
use \Graze\TelnetClient\TelnetClient;
21
use \Graze\Dynamark3Client\Dynamark3Constants;
22
23
class Dynamark3Client implements Dynamark3ClientInterface
24
{
25
    /**
26
     * @var TelnetClientInterface
27
     */
28
    protected $telnet;
29
30
    /**
31
     * @var CommandResolver
32
     */
33
    protected $commandResolver;
34
35
    /**
36
     * @param TelnetClientInterface $telnet
37
     * @param CommandResolver       $commandResolver
38
     */
39 3
    public function __construct(TelnetClientInterface $telnet, CommandResolver $commandResolver)
40
    {
41 3
        $this->telnet = $telnet;
42 3
        $this->commandResolver = $commandResolver;
43 3
    }
44
45
    /**
46
     * @param string $dsn
47
     */
48 1
    public function connect($dsn)
49
    {
50 1
        $this->telnet->connect(
51 1
            $dsn,
52 1
            Dynamark3Constants::PROMPT,
53 1
            Dynamark3Constants::PROMPT_ERROR,
54 1
            Dynamark3Constants::LINE_ENDING
55
        );
56 1
    }
57
58
    /**
59
     * @param string $name
60
     * @param array  $arguments
61
     *
62
     * @return Dynamark3ResponseInterface
63
     */
64 1
    public function __call($name, array $arguments)
65
    {
66 1
        $command = $this->commandResolver->resolve($name);
67 1
        $telnetResponse = $this->telnet->execute(
68 1
            $command->getCommandText() . $command->getArgumentText($arguments),
69 1
            $command->getPrompt()
70
        );
71
72 1
        return $command->parseResponse($telnetResponse);
73
    }
74
75
    /**
76
     * @return Dynamark3Client
77
     */
78 1
    public static function factory()
79
    {
80 1
        return new static(
81 1
            TelnetClient::factory(),
82 1
            new CommandResolver()
83
        );
84
    }
85
}
86