Completed
Push — master ( 52cc4c...9e125a )
by Kamil
11s
created

Driver::parseResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace Dazzle\Redis\Driver;
3
4
use Clue\Redis\Protocol\Model\ModelInterface;
5
use Clue\Redis\Protocol\Model\Request;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Dazzle\Redis\Driver\Request.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use Clue\Redis\Protocol\Parser\RequestParser;
7
use Clue\Redis\Protocol\Parser\ResponseParser;
8
use Clue\Redis\Protocol\Serializer\RecursiveSerializer;
9
10
class Driver implements DriverInterface
11
{
12
    /**
13
     * @var RequestParser
14
     */
15
    protected $requestParser;
16
17
    /**
18
     * @var ResponseParser
19
     */
20
    protected $responseParser;
21
22
    /**
23
     * @var RecursiveSerializer
24
     */
25
    protected $serializer;
26
27
    /**
28
     *
29
     */
30
    public function __construct()
31
    {
32
        $this->requestParser = new RequestParser();
33
        $this->responseParser = new ResponseParser();
34
        $this->serializer = new RecursiveSerializer();
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40 1
    public function commands(Request $request)
41
    {
42 1
        return $this->serializer->getRequestMessage(
43 1
            $request->getCommand(),
44 1
            $request->getArgs()
45
        );
46
    }
47
48
    /**
49
     * @return RecursiveSerializer
50
     */
51
    public function getSerializer()
52
    {
53
        return $this->serializer;
54
    }
55
56
    /**
57
     * @return RequestParser
58
     */
59
    public function getRequestParser()
60
    {
61
        return $this->requestParser;
62
    }
63
64
    /**
65
     * @return ResponseParser
66
     */
67
    public function getResponseParser()
68
    {
69
        return $this->responseParser;
70
    }
71
72
    /**
73
     * @param $data
74
     * @return ModelInterface[]
75
     */
76 1
    public function parseResponse($data)
77
    {
78 1
        return $this->responseParser->pushIncoming($data);
79
    }
80
81
    /**
82
     * @param $data
83
     * @return string
84
     */
85
    public function buildResponse($data)
86
    {
87
        return $this->serializer->getReplyMessage($data);
88
    }
89
90
}