Completed
Pull Request — master (#26)
by X
02:21
created

IntegerParser::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 5
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
1
<?php
2
/**
3
 * parser for PHP serialized integer
4
 */
5
namespace xKerman\Restricted;
6
7
/**
8
 * Parser for PHP serialized integer
9
 */
10 View Code Duplication
class IntegerParser implements ParserInterface
0 ignored issues
show
Duplication introduced by
This class 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...
11
{
12
    /** @var ParserInterface $parser internal parser for integer parsing */
13
    private $parser;
14
15
    /**
16
     * constructor
17
     */
18 17
    public function __construct()
19
    {
20 17
        $this->parser = new RegexpSubstringParser('/\Gi:[+-]?[0-9]+;/', 2, -1);
21 17
    }
22
23
    /**
24
     * parse given `$source` as PHP serialized integer
25
     *
26
     * @param Source $source parser input
27
     * @return array
28
     * @throws UnserializeFailedException
29
     */
30 17
    public function parse(Source $source)
31
    {
32 17
        list($result, $source) = $this->parser->parse($source);
33 7
        return array(intval($result, 10), $source);
34
    }
35
}
36