Completed
Pull Request — master (#204)
by Ryan
11:34
created

BooleanType::isValidValue()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 2
nc 7
nop 1
crap 30
1
<?php
2
/**
3
 * Copyright (c) 2015–2018 Alexandr Viniychuk <http://youshido.com>.
4
 * Copyright (c) 2015–2018 Portey Vasil <https://github.com/portey>.
5
 * Copyright (c) 2018 Ryan Parman <https://github.com/skyzyx>.
6
 * Copyright (c) 2018 Ashley Hutson <https://github.com/asheliahut>.
7
 * Copyright (c) 2015–2018 Contributors.
8
 *
9
 * http://opensource.org/licenses/MIT
10
 */
11
12
declare(strict_types=1);
13
/*
14 9
 * This file is a part of graphql-youshido project.
15
 *
16 9
 * @author Alexandr Viniychuk <[email protected]>
17
 * created: 11/27/15 1:22 AM
18
 */
19 9
20
namespace Youshido\GraphQL\Type\Scalar;
21 9
22 1
class BooleanType extends AbstractScalarType
23
{
24 9
    public function getName()
25 1
    {
26
        return 'Boolean';
27
    }
28 9
29
    public function serialize($value)
30
    {
31 9
        if ('true' === $value) {
32
            return true;
33 9
        }
34
35
        if ('false' === $value) {
36 5
            return false;
37
        }
38 5
39
        return (bool) $value;
40
    }
41
42
    public function isValidValue($value)
43
    {
44
        return null === $value || \is_bool($value) || (\is_int($value) && (0 === $value || 1 === $value));
45
    }
46
47
    public function getDescription()
48
    {
49
        return 'The `Boolean` scalar type represents `true` or `false`.';
50
    }
51
}
52