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

StringType   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

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