Passed
Pull Request — master (#25)
by
unknown
13:18
created

ODMArrayType   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A registerODMType() 0 13 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 Symfony\Component\Serializer\SerializerInterface;
12
13
class ODMArrayType extends AbstractODMType
14
{
15 2
    public static function registerODMType(string $entityClass, SerializerInterface $serializer): void
16
    {
17 2
        if (!class_exists($entityClass) && !interface_exists($entityClass)) {
18
            throw new \DomainException(sprintf('Class or interface "%s" does not exist.', $entityClass));
19
        }
20
21 2
        $typeName = sprintf('%s[]', $entityClass);
22 2
        self::addType($typeName, static::class);
23
24
        /** @var ODMType $type */
25 2
        $type = self::getType($typeName);
26 2
        $type->setEntityClass($typeName);
27 2
        $type->setSerializer($serializer);
28
    }
29
}