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

TimestampType::serialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4286
cc 2
eloc 4
nc 2
nop 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
12
class TimestampType extends AbstractScalarType
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->getTimestamp();
26
    }
27
28
    public function isValidValue($value)
29
    {
30
        if (is_object($value)) {
31
            return true;
32
        }
33
34
        return is_int($value);
35
    }
36
37
    public function getDescription()
38
    {
39
        return 'A sequence of characters or encoded information identifying when a certain event occurred in seconds';
40
    }
41
42
}