Passed
Pull Request — master (#45)
by X
02:29
created

xKerman_Restricted_ExpressionParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 48.65 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 18
loc 37
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parse() 18 18 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * Parser for serialized PHP values
5
 */
6
class xKerman_Restricted_ExpressionParser implements xKerman_Restricted_ParserInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /** @var array $handlers handlers list to use */
9
    private $handlers;
10
    /**
11
     * constructor
12
     */
13
    public function __construct()
14
    {
15
        $this->handlers = array('N' => new xKerman_Restricted_NullHandler(), 'b' => new xKerman_Restricted_BooleanHandler(), 'i' => new xKerman_Restricted_IntegerHandler(), 'd' => new xKerman_Restricted_FloatHandler(), 's' => new xKerman_Restricted_StringHandler(), 'S' => new xKerman_Restricted_EscapedStringHandler(), 'a' => new xKerman_Restricted_ArrayHandler($this));
16
    }
17
    /**
18
     * parse given `$source` as PHP serialized value
19
     *
20
     * @param Source $source parser input
0 ignored issues
show
Documentation introduced by
Should the type for parameter $source not be xKerman_Restricted_Source?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
21
     * @return array
22
     * @throws UnserializeFailedException
23
     */
24 View Code Duplication
    public function parse(xKerman_Restricted_Source $source)
0 ignored issues
show
Duplication introduced by
This method 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...
25
    {
26
        $matches = $source->match('/\\G(?|
27
            (s):([0-9]+):"
28
            |(i):([+-]?[0-9]+);
29
            |(a):([0-9]+):{
30
            |(d):((?:
31
                [+-]?(?:[0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+|[0-9]+)(?:[eE][+-]?[0-9]+)?)
32
                |-?INF
33
                |NAN);
34
            |(b):([01]);
35
            |(N);
36
            |(S):([0-9]+):"
37
        )/x');
38
        $tag = $matches[0];
39
        $args = isset($matches[1]) ? $matches[1] : null;
40
        return $this->handlers[$tag]->handle($source, $args);
41
    }
42
}