Completed
Push — master ( 41762b...d48513 )
by John
05:24 queued 03:02
created

AbstractCommand::getArgumentText()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2.0116
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
12
 * @link https://github.com/graze/dynamark3-client
13
 */
14
15
namespace Graze\Dynamark3Client\Command;
16
17
use \Graze\Dynamark3Client\Command\CommandInterface;
18
use \Graze\TelnetClient\TelnetResponseInterface;
19
use \Graze\Dynamark3Client\Dynamark3Response;
20
use \Graze\Dynamark3Client\Dynamark3Constants;
21
22
abstract class AbstractCommand implements CommandInterface
23
{
24
    /**
25
     * @return string
26
     */
27
    abstract public function getCommandText();
28
29
    /**
30
     * @param array $arguments
31
     *
32
     * @return string
33
     */
34 2
    public function getArgumentText(array $arguments)
35
    {
36 2
        if (empty($arguments)) {
37
            return '';
38
        }
39
40
        // add quotes to arguments
41 2
        array_walk($arguments, function (&$value) {
42 2
            $value = sprintf('"%s"', $value);
43 2
        });
44
45 2
        return ' ' . implode(' ', $arguments);
46
    }
47
48
    /**
49
     * Default to the TelnetClient's prompt
50
     *
51
     * @return string
52
     */
53 2
    public function getPrompt()
54
    {
55 2
        return null;
56
    }
57
58
    /**
59
     * @param TelnetResponseInterface $response
60
     *
61
     * @return \Graze\Dynamark3Client\Dynamark3ResponseInterface
62
     */
63 6 View Code Duplication
    public function parseResponse(TelnetResponseInterface $response)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65 6
        $errorCode = null;
66 6
        $promptMatches = $response->getPromptMatches();
67 6
        $prompt = reset($promptMatches);
68 6
        if ($response->isError()) {
69
            // error prompt - ERROR nnn
70 3
            $errorCode = substr($prompt, 6);
71 3
        }
72
73 6
        return new Dynamark3Response(
74 6
            $prompt,
75
            $errorCode
76 6
        );
77
    }
78
}
79