Failed Conditions
Push — master ( fab761...8502a7 )
by Adrien
03:06
created

TimeType   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 15
c 1
b 0
f 0
dl 0
loc 38
rs 10
ccs 17
cts 17
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToDatabaseValue() 0 11 3
A convertToPHPValue() 0 17 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\DBAL\Types;
6
7
use Cake\Chronos\ChronosTime;
1 ignored issue
show
Bug introduced by
The type Cake\Chronos\ChronosTime was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Doctrine\DBAL\Platforms\AbstractPlatform;
9
use Doctrine\DBAL\Types\ConversionException;
10
11
final class TimeType extends \Doctrine\DBAL\Types\TimeType
12
{
13
    /**
14
     * @return ($value is null ? null : string)
15
     */
16 2
    public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
17
    {
18 2
        if ($value === null) {
19 1
            return $value;
20
        }
21
22 2
        if ($value instanceof ChronosTime) {
23 1
            return $value->format($platform->getTimeFormatString());
24
        }
25
26 1
        throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'ChronosTime']);
27
    }
28
29
    /**
30
     * @return ($value is null ? null : ChronosTime)
31
     */
32 2
    public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?ChronosTime
33
    {
34 2
        if ($value === null || $value instanceof ChronosTime) {
35 1
            return $value;
36
        }
37
38 2
        if (!is_string($value)) {
39 1
            throw ConversionException::conversionFailedFormat(
40 1
                $value,
41 1
                $this->getName(),
42 1
                $platform->getTimeFormatString(),
43 1
            );
44
        }
45
46 1
        $val = new ChronosTime($value);
47
48 1
        return $val;
49
    }
50
}
51