AbstractCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 25 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 15
loc 60
ccs 19
cts 20
cp 0.95
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
getCommandText() 0 1 ?
A getArgumentText() 0 16 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(
42 2
            $arguments,
43 2
            function (&$value) {
44 2
                $value = sprintf('"%s"', $value);
45 2
            }
46
        );
47
48 2
        return ' ' . implode(' ', $arguments);
49
    }
50
51
    /**
52
     * Default to the TelnetClient's prompt
53
     *
54
     * @return string
55
     */
56 2
    public function getPrompt()
57
    {
58 2
        return null;
59
    }
60
61
    /**
62
     * @param TelnetResponseInterface $response
63
     *
64
     * @return \Graze\Dynamark3Client\Dynamark3ResponseInterface
65
     */
66 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...
67
    {
68 6
        $errorCode = null;
69 6
        $promptMatches = $response->getPromptMatches();
70 6
        $prompt = reset($promptMatches);
71 6
        if ($response->isError()) {
72
            // error prompt - ERROR nnn
73 3
            $errorCode = substr($prompt, 6);
74
        }
75
76 6
        return new Dynamark3Response(
77 6
            $prompt,
78 6
            $errorCode
79
        );
80
    }
81
}
82