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

xKerman_Restricted_FloatHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A handle() 7 7 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
 * Handler for PHP serialized float number
5
 */
6 View Code Duplication
class xKerman_Restricted_FloatHandler implements xKerman_Restricted_HandlerInterface
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...
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 $mapping parser result mapping */
9
    private $mapping;
10
    /**
11
     * constructor
12
     */
13
    public function __construct()
14
    {
15
        $this->mapping = array('INF' => INF, '-INF' => -INF, 'NAN' => NAN);
16
    }
17
    /**
18
     * parse given `$source` as PHP serialized float number
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
     * @param string $args   float value
22
     * @return array
23
     * @throws UnserializeFailedException
24
     */
25
    public function handle(xKerman_Restricted_Source $source, $args)
26
    {
27
        if (array_key_exists($args, $this->mapping)) {
28
            return array($this->mapping[$args], $source);
29
        }
30
        return array(floatval($args), $source);
31
    }
32
}