Completed
Push — master ( bd44b4...5fafbf )
by Portey
03:31
created

DateType::isValidValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 6
loc 6
rs 9.4286
cc 2
eloc 3
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 View Code Duplication
class DateType 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');
26
    }
27
28
    public function isValidValue($value)
29
    {
30
        $d = \DateTime::createFromFormat('Y-m-d', $value);
31
32
        return $d && $d->format('Y-m-d') == $value;
33
    }
34
35
}