FloatType::coerceLiteral()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 12
ccs 0
cts 7
cp 0
rs 8.8571
cc 5
eloc 6
nc 3
nop 1
crap 30
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