Completed
Pull Request — master (#2)
by
unknown
02:18
created

Redis::handleStop()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 3
cts 5
cp 0.6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.2559
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 88.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Dazzle\Redis;
4
5
use Dazzle\Promise\Deferred;
6
use Dazzle\Redis\Command\Enum;
7
use Dazzle\Loop\LoopInterface;
8
use Dazzle\Loop\LoopAwareTrait;
9
use Dazzle\Redis\Driver\Request;
10
use Dazzle\Redis\Command\Builder;
11
use Dazzle\Promise\PromiseInterface;
12
use Dazzle\Throwable\Exception\RuntimeException;
13
use Error;
14
15
class Redis
0 ignored issues
show
Bug introduced by
There is one abstract method dispatch in this class; you could implement it, or declare this class as abstract.
Loading history...
16
{
17
    use LoopAwareTrait;
18
    use Command\Compose\ApiChannelTrait;
19
    use Command\Compose\ApiClusterTrait;
20
    use Command\Compose\ApiConnTrait;
21
    use Command\Compose\ApiCoreTrait;
22
    use Command\Compose\ApiGeospatialTrait;
23
    use Command\Compose\ApiHyperLogTrait;
24
    use Command\Compose\ApiKeyValTrait;
25
    use Command\Compose\ApiListTrait;
26
    use Command\Compose\ApiSetTrait;
27
    use Command\Compose\ApiSetHashTrait;
28
    use Command\Compose\ApiSetSortedTrait;
29
    use Command\Compose\ApiTransactionTrait;
30
31
    /**
32
     * @var string
33
     */
34
    protected $endpoint;
35
36
    /**
37
     * @param string $endpoint
38
     * @param LoopInterface $loop
39
     */
40
    public function __construct($endpoint, LoopInterface $loop)
41
    {
42
        $this->endpoint = $endpoint;
43
        $this->loop = $loop;
44
        $this->dispatcher = new Dispatcher($loop);
0 ignored issues
show
Bug introduced by
The property dispatcher does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
45
        $this->driver = $this->dispatcher->getDriver();
0 ignored issues
show
Bug introduced by
The property driver does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
46
    }
47
48
    /**
49
     *
50
     */
51
    public function __destruct()
52
    {
53
54
    }
55
56
    /**
57
     * Pipe Redis request.
58
     *
59
     * @param Request $command
60
     * @return PromiseInterface
61
     */
62
    private function pipe(Request $command)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
63
    {
64
        $request = new Deferred();
65
        $promise = $request->getPromise();
66
        if ($this->dispatcher->isEnding())
67
        {
68
            $request->reject(new RuntimeException('Connection closed'));
69
        } 
70
        else 
71
        {
72
            $payload = $this->driver->commands($command);
73
74
            $this->dispatcher->on('request', function () use ($payload) {
75
                $this->dispatcher->handleRequest($payload);
76
            });
77
78
            $this->dispatcher->appendRequest($request);
79
        }
80
81
        return $promise;
82
    }
83
84
    public function connect($config = [])
0 ignored issues
show
Unused Code introduced by
The parameter $config 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...
85
    {
86
        $this->dispatcher->watch($this->endpoint);
87
    }
88
};
89