Completed
Pull Request — master (#154)
by
unknown
04:04
created

BooleanType::serialize()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3
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 BooleanType extends AbstractScalarType
13
{
14 7
    public function getName()
15
    {
16 7
        return 'Boolean';
17
    }
18
19 7
    public function serialize($value)
20
    {
21 7
        if ($value === 'true') {
22 1
            return true;
23
        }
24 7
        if ($value === 'false') {
25 1
            return false;
26
        }
27
28 7
        return (bool)$value;
29
    }
30
31 7
    public function isValidValue($value)
32
    {
33 7
        return is_null($value) || is_bool($value);
34
    }
35
36 3
    public function getDescription()
37
    {
38 3
        return 'The `Boolean` scalar type represents `true` or `false`.';
39
    }
40
41
}
42