IntType::serialize()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
ccs 7
cts 7
cp 1
cc 4
nc 4
nop 1
crap 4
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