Completed
Push — master ( d52ee7...e7842c )
by Alexandr
03:54
created

StringType::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 6
rs 9.4285
ccs 3
cts 3
cp 1
cc 1
eloc 4
nc 1
nop 0
crap 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:05 AM
7
*/
8
9
namespace Youshido\GraphQL\Type\Scalar;
10
11
12
class StringType extends AbstractScalarType
13
{
14
15 45
    public function getName()
16
    {
17 45
        return 'String';
18
    }
19
20 14
    public function serialize($value)
21
    {
22 14
        if ($value === true) {
23 2
            return 'true';
24 14
        } elseif ($value === false) {
25 1
            return 'false';
26 14
        } elseif ($value === null) {
27 5
            return null;
28
        }
29
30 14
        if(is_array($value)) {
31 1
            return '';
32
        }
33
34 14
        return (string) $value;
35
    }
36
37 88
    public function isValidValue($value)
38
    {
39 88
        return is_string($value);
40
    }
41
42 3
    public function getDescription()
43
    {
44
        return 'The `String` scalar type represents textual data, represented as UTF-8 ' .
45 3
               'character sequences. The String type is most often used by GraphQL to ' .
46 3
               'represent free-form human-readable text.';
47
    }
48
49
}
50