Passed
Pull Request — master (#13)
by Alexander
22:05 queued 16:22
created

ODMType::convertToDatabaseValue()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.9666
cc 3
nc 4
nop 2
crap 3
1
<?php
2
/*
3
 * This file is part of Goodwix Doctrine JSON ODM.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Goodwix\DoctrineJsonOdm\Type;
10
11
use Doctrine\DBAL\Platforms\AbstractPlatform;
12
use Doctrine\DBAL\Types\JsonType;
13
use Goodwix\DoctrineJsonOdm\Exception\JsonOdmException;
14
use Symfony\Component\Serializer\Exception\ExceptionInterface;
15
use Symfony\Component\Serializer\SerializerInterface;
16
17
class ODMType extends AbstractODMType
18
{
19 5
    public static function registerODMType(string $entityClass, SerializerInterface $serializer): void
20
    {
21 5
        if (!class_exists($entityClass) && !interface_exists($entityClass)) {
22 1
            throw new \DomainException(sprintf('Class or interface "%s" does not exist.', $entityClass));
23
        }
24
25 4
        self::addType($entityClass, static::class);
26
27
        /** @var ODMType $type */
28 4
        $type = self::getType($entityClass);
29 4
        $type->setEntityClass($entityClass);
30 4
        $type->setSerializer($serializer);
31 4
    }
32
}
33