Completed
Push — master ( 0b7ef3...f36d8f )
by Alexandr
03:51
created

TestTimeType   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 0
cbo 1
dl 38
loc 38
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 4 4 1
A serialize() 8 8 3
A isValidValue() 10 10 3
A getDescription() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 8/14/16 12:26 PM
7
*/
8
9
namespace Youshido\Tests\DataProvider;
10
11
12
use Youshido\GraphQL\Type\Scalar\AbstractScalarType;
13
14 View Code Duplication
class TestTimeType 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...
15
{
16
17
    public function getName()
18
    {
19
        return 'TestTime';
20
    }
21
22
    /**
23
     * @param $value \DateTime
24
     * @return null|string
25
     */
26
    public function serialize($value)
27
    {
28
        if ($value === null) {
29
            return null;
30
        }
31
32
        return $value instanceof \DateTime ? $value->format('H:i:s') : $value;
33
    }
34
35
    public function isValidValue($value)
36
    {
37
        if (is_object($value)) {
38
            return true;
39
        }
40
41
        $d = \DateTime::createFromFormat('H:i:s', $value);
42
43
        return $d && $d->format('H:i:s') == $value;
44
    }
45
46
    public function getDescription()
47
    {
48
        return 'Representation time in "H:i:s" format';
49
    }
50
51
}