DateTimeType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 43
loc 43
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToPHPValue() 12 12 3
A convertToDatabaseValue() 7 7 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 declare (strict_types = 1);
2
3
namespace Limoncello\Flute\Types;
4
5
/**
6
 * Copyright 2015-2019 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use DateTimeInterface;
22
use Doctrine\DBAL\Platforms\AbstractPlatform;
23
use Doctrine\DBAL\Types\ConversionException;
24
use Doctrine\DBAL\Types\DateTimeType as BaseDateTimeType;
25
use Exception;
26
use function assert;
27
28
/**
29
 * @package Limoncello\Flute
30
 */
31 View Code Duplication
class DateTimeType extends BaseDateTimeType
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...
32
{
33
    use TypeTrait;
34
35
    /** Type name */
36
    const NAME = 'limoncelloDateTime';
37
38
    /**
39
     * @inheritdoc
40
     *
41
     * @return DateTime|null
42
     *
43
     * @throws ConversionException
44
     * @throws Exception
45
     *
46
     * @SuppressWarnings(PHPMD.StaticAccess)
47 35
     */
48
    public function convertToPHPValue($value, AbstractPlatform $platform)
49 35
    {
50
        $result = null;
51 35
52 35
        if ($value !== null && ($dateTimeOrNull = parent::convertToPHPValue($value, $platform)) !== null) {
53
            assert($dateTimeOrNull instanceof DateTimeInterface);
54 35
            // despite the name it's not null already
55
            $result = DateTime::createFromDateTime($dateTimeOrNull);
56
        }
57 35
58
        return $result;
59
    }
60
61
    /**
62
     * @inheritdoc
63
     *
64
     * @throws ConversionException
65 14
     */
66
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
67 14
    {
68 14
        return parent::convertToDatabaseValue(
69 12
            $this->convertToDateTimeFromString($value, $platform->getDateTimeFormatString(), static::NAME),
70
            $platform
71
        );
72
    }
73
}
74