IntType   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 0
loc 37
rs 10
c 0
b 0
f 0
ccs 15
cts 15
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A serialize() 0 14 4
A isValidValue() 0 4 2
A getDescription() 0 7 1
1
<?php
2
/*
3
* This file is a part of graphql-youshido project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 11/27/15 1:22 AM
7
*/
8
9
namespace Youshido\GraphQL\Type\Scalar;
10
11
12
class IntType extends AbstractScalarType
13
{
14
15 15
    public function getName()
16
    {
17 15
        return 'Int';
18
    }
19
20 12
    public function serialize($value)
21
    {
22 12
        if ($value === null) {
23 2
            return null;
24
        } else {
25 12
            if (is_int($value)) {
26 12
                return $value;
27
            } else {
28 1
                $value = (int)$value;
29
30 1
                return $value != 0 ? $value : null;
31
            }
32
        }
33
    }
34
35 15
    public function isValidValue($value)
36
    {
37 15
        return is_null($value) || is_int($value);
38
    }
39
40 5
    public function getDescription()
41
    {
42
        return 'The `Int` scalar type represents non-fractional signed whole numeric ' .
43 5
               'values. Int can represent values between -(2^53 - 1) and 2^53 - 1 since ' .
44 5
               'represented in JSON as double-precision floating point numbers specified' .
45 5
               'by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).';
46
    }
47
48
}
49