Completed
Push — master ( a293a3...292fca )
by X
02:23
created

StringHandler::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * handler for serialized string
4
 */
5
namespace xKerman\Restricted;
6
7
/**
8
 * Handler class for parse serialized PHP stirng
9
 */
10
class StringHandler implements HandlerInterface
11
{
12
    /** @var integer */
13
    const CLOSE_STRING_LENGTH = 2;
14
15
    /**
16
     * parse give `$source` as PHP serialized string
17
     *
18
     * @param Source $source parser input
19
     * @param string $args   string length
20
     * @return array parser result
21
     * @throws UnserializeFailedException
22
     */
23 10
    public function handle(Source $source, $args)
24
    {
25 10
        $length = intval($args, 10);
26 10
        $result = $source->read($length);
27 10
        $source->consume('";', self::CLOSE_STRING_LENGTH);
28
29 9
        return array($result, $source);
30
    }
31
}
32