Completed
Push — master ( 5fafbf...34c1d6 )
by Portey
02:57
created

DateTimeType::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 View Code Duplication
class DateTimeType extends AbstractScalarType
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
15
    /**
16
     * @param $value \DateTime
17
     * @return null|string
18
     */
19
    public function serialize($value)
20
    {
21
        if ($value === null) {
22
            return null;
23
        }
24
25
        return $value->format('Y-m-d H:i:s');
26
    }
27
28
    public function isValidValue($value)
29
    {
30
        if (is_object($value)) {
31
            return true;
32
        }
33
34
        $d = \DateTime::createFromFormat('Y-m-d H:i:s', $value);
35
36
        return $d && $d->format('Y-m-d H:i:s') == $value;
37
    }
38
39
    public function getDescription()
40
    {
41
        return 'Representation of date and time in "Y-m-d H:i:s" format';
42
    }
43
44
    public function getName()
45
    {
46
        return 'DateTime';
47
    }
48
49
50
}