DateTimeType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 30
loc 30
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 4 4 1
A getter() 4 4 2
A setter() 4 4 2

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
/*
4
 * This file is part of the PhpMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpMob\Settings\Type;
15
16
/**
17
 * @author Ishmael Doss <[email protected]>
18
 */
19 View Code Duplication
class DateTimeType implements TypeInterface
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...
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public static function getName()
25
    {
26
        return 'datetime';
27
    }
28
29
    /**
30
     * @param mixed $value
31
     *
32
     * @return string
33
     */
34
    public function getter($value)
35
    {
36
        return \DateTime::createFromFormat('Y-m-d H:i:s', $value) ?: null;
37
    }
38
39
    /**
40
     * @param mixed $value
41
     *
42
     * @return string
43
     */
44
    public function setter($value)
45
    {
46
        return $value ? $value->format('Y-m-d H:i:s') : null;
47
    }
48
}
49