LTreeType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 16
c 1
b 0
f 0
dl 0
loc 39
ccs 18
cts 18
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSQLDeclaration() 0 3 1
A convertToPHPValue() 0 11 2
A getName() 0 3 1
A convertToDatabaseValue() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Umbrellio\LTree\Types;
6
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Doctrine\DBAL\Types\Type;
9
10
class LTreeType extends Type
11
{
12
    public const TYPE_NAME = 'ltree';
13
    public const TYPE_SEPARATE = '.';
14
15 1
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
16
    {
17 1
        return static::TYPE_NAME;
18
    }
19
20 3
    public function convertToPHPValue($value, AbstractPlatform $platform): ?array
21
    {
22 3
        if ($value === null) {
23 1
            return null;
24
        }
25
26 2
        return collect(explode(static::TYPE_SEPARATE, (string) $value))
0 ignored issues
show
Bug introduced by
explode(static::TYPE_SEPARATE, (string)$value) of type string[] is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        return collect(/** @scrutinizer ignore-type */ explode(static::TYPE_SEPARATE, (string) $value))
Loading history...
27 2
            ->map(static function ($value) {
28 2
                return (int) $value;
29 2
            })
30 2
            ->toArray();
31
    }
32
33 4
    public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
34
    {
35 4
        if ($value === null) {
36 1
            return null;
37
        }
38
39 3
        if (is_scalar($value)) {
40 1
            $value = (array) $value;
41
        }
42
43 3
        return implode(static::TYPE_SEPARATE, $value);
44
    }
45
46 1
    public function getName(): string
47
    {
48 1
        return self::TYPE_NAME;
49
    }
50
}
51