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

AbstractCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 26.32 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 94.74%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 0
cbo 2
dl 15
loc 57
ccs 18
cts 19
cp 0.9474
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
getCommandText() 0 1 ?
A getArgumentText() 0 13 2
A getPrompt() 0 4 1
A parseResponse() 15 15 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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