IntType   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 35
Duplicated Lines 34.29 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 81.82%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 2
dl 12
loc 35
ccs 9
cts 11
cp 0.8182
rs 10

2 Methods

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

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\IntValue;
7
use Fubhy\GraphQL\Type\Definition\Types\ScalarType;
8
9
class IntType extends ScalarType
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $name = 'Int';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 75
    public function coerce($value)
20
    {
21 75
        if ((is_numeric($value) && $value <= PHP_INT_MAX && $value >= -PHP_INT_MAX) || is_bool($value)) {
22 66
            return (int) $value;
23
        }
24
25 9
        return NULL;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 6 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...
32
    {
33 6
        if ($node instanceof IntValue) {
34 6
            $num = $node->get('value');
35
36 6
            if ($num <= PHP_INT_MAX && $num >= -PHP_INT_MAX) {
37 6
                return intval($num);
38
            }
39
        }
40
41
        return NULL;
42
    }
43
}
44