FloatType   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 31
Duplicated Lines 38.71 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 22.22%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 1
dl 12
loc 31
ccs 2
cts 9
cp 0.2222
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A coerce() 0 4 3
B coerceLiteral() 12 12 5

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 Fubhy\GraphQL\Type\Definition\Types\Scalars;
4
5
use Fubhy\GraphQL\Language\Node;
6
use Fubhy\GraphQL\Language\Node\FloatValue;
7
use Fubhy\GraphQL\Language\Node\IntValue;
8
use Fubhy\GraphQL\Type\Definition\Types\ScalarType;
9
10
class FloatType extends ScalarType
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $name = 'Float';
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 27
    public function coerce($value)
21
    {
22 27
        return is_numeric($value) || is_bool($value) ? (float) $value : NULL;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 View Code Duplication
    public function coerceLiteral(Node $node)
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...
29
    {
30
        if ($node instanceof IntValue || $node instanceof FloatValue) {
31
            $num = (float) $node->get('value');
32
33
            if ($num <= PHP_INT_MAX && $num >= -PHP_INT_MAX) {
34
                return $num;
35
            }
36
        }
37
38
        return NULL;
39
    }
40
}
41