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

BooleanType   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 0
loc 30
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A serialize() 0 12 3
B isValidValue() 0 4 5
A getDescription() 0 4 1
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