DNumber   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 10.34 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 1
dl 6
loc 58
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubNodeNames() 0 3 1
C parse() 6 28 7

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
namespace PhpParser\Node\Scalar;
4
5
use PhpParser\Node\Scalar;
6
7
class DNumber extends Scalar
8
{
9
    /** @var float Number value */
10
    public $value;
11
12
    /**
13
     * Constructs a float number scalar node.
14
     *
15
     * @param float $value      Value of the number
16
     * @param array $attributes Additional attributes
17
     */
18
    public function __construct($value, array $attributes = array()) {
19
        parent::__construct($attributes);
20
        $this->value = $value;
21
    }
22
23
    public function getSubNodeNames() {
24
        return array('value');
25
    }
26
27
    /**
28
     * @internal
29
     *
30
     * Parses a DNUMBER token like PHP would.
31
     *
32
     * @param string $str A string number
33
     *
34
     * @return float The parsed number
35
     */
36
    public static function parse($str) {
37
        // if string contains any of .eE just cast it to float
38
        if (false !== strpbrk($str, '.eE')) {
39
            return (float) $str;
40
        }
41
42
        // otherwise it's an integer notation that overflowed into a float
43
        // if it starts with 0 it's one of the special integer notations
44
        if ('0' === $str[0]) {
45
            // hex
46 View Code Duplication
            if ('x' === $str[1] || 'X' === $str[1]) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
47
                return hexdec($str);
48
            }
49
50
            // bin
51 View Code Duplication
            if ('b' === $str[1] || 'B' === $str[1]) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
52
                return bindec($str);
53
            }
54
55
            // oct
56
            // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9)
57
            // so that only the digits before that are used
58
            return octdec(substr($str, 0, strcspn($str, '89')));
59
        }
60
61
        // dec
62
        return (float) $str;
63
    }
64
}
65