ReadResponse::parse()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 8
nop 0
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace seregazhuk\React\Memcached\Protocol\Response;
4
5
use seregazhuk\React\Memcached\Protocol\Parser;
6
7
class ReadResponse extends Response
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12
    public function parse()
13
    {
14
        $regExp = '/VALUE [^\s]+ \d+ \d+' . Parser::COMMAND_SEPARATOR . '(.*)' . Parser::COMMAND_SEPARATOR . 'END/';
15
        preg_match($regExp, $this->data, $match);
16
17
        $value = isset($match[1]) ? trim($match[1]) : null;
18
19
        if (null === $value) {
20
            $this->fail();
21
        }
22
23
        // Unserialize non-numeric values
24
        return is_numeric($value) ? $value : unserialize($value);
25
    }
26
}
27