Completed
Push — master ( 118ce9...9e4cdb )
by Alexandr
02:51
created

DateTimeTzType::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
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:22 AM
7
*/
8
9
namespace Youshido\GraphQL\Type\Scalar;
10
11 View Code Duplication
class DateTimeTzType 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...
12
{
13 3
    public function getName()
14
    {
15 3
        return 'DateTimeTz';
16
    }
17
18
    /**
19
     * @param $value \DateTime
20
     * @return null|string
21
     */
22 1
    public function serialize($value)
23
    {
24 1
        if ($value === null) {
25 1
            return null;
26
        }
27
28 1
        return $value->format('r');
29
    }
30
31 2
    public function parseValue($value)
32
    {
33 2
        return is_object($value) ? $this->serialize($value) : $value;
34
    }
35
36 2
    public function isValidValue($value)
37
    {
38 2
        if (is_object($value)) {
39 1
            return true;
40
        }
41
42 2
        $d = \DateTime::createFromFormat('D, d M Y H:i:s O', $value);
43
44 2
        return $d && $d->format('r') == $value;
45
    }
46
47 1
    public function getDescription()
48
    {
49 1
        return 'Representation of date and time in "r" format';
50
    }
51
52
}
53