Completed
Push — master ( 9e125a...9a1e57 )
by Kamil
02:25
created

ApiConnTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 12.73 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 7
loc 55
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1
ccs 0
cts 14
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
dispatch() 0 1 ?
A auth() 0 7 1
A ping() 7 7 1
A quit() 0 6 1
A select() 0 7 1

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
namespace Dazzle\Redis\Command\Compose;
4
5
use Dazzle\Redis\Command\Builder;
6
use Dazzle\Redis\Command\Enum;
7
use Dazzle\Redis\Driver\Request;
8
9
trait ApiConnTrait
10
{
11
    /**
12
     * @param Request $request
13
     * @return mixed
14
     */
15
    abstract function dispatch(Request $request);
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
16
17
    /**
18
     * @override
19
     * @inheritDoc
20
     */
21
    public function auth($password)
22
    {
23
        $command = Enum::AUTH;
24
        $args = [$password];
25
26
        return $this->dispatch(Builder::build($command, $args));
27
    }
28
29
    /**
30
     * @override
31
     * @inheritDoc
32
     */
33 View Code Duplication
    public function ping($message = 'PING')
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...
34
    {
35
        $command = Enum::PING;
36
        $args = [$message];
37
38
        return $this->dispatch(Builder::build($command, $args));
39
    }
40
41
    /**
42
     * @override
43
     * @inheritDoc
44
     */
45
    public function quit()
46
    {
47
        $command = Enum::QUIT;
48
49
        return $this->dispatch(Builder::build($command));
50
    }
51
52
    /**
53
     * @override
54
     * @inheritDoc
55
     */
56
    public function select($index)
0 ignored issues
show
Unused Code introduced by
The parameter $index is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    {
58
        // TODO: Implement select() method.
59
        $command = Enum::SELECT;
0 ignored issues
show
Unused Code introduced by
$command is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
60
61
        return $this;
62
    }
63
}
64