LinkObjectMap::getWantedType()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
4
namespace Apie\OpenapiSchema\Map;
5
6
use Apie\CompositeValueObjects\Exceptions\InvalidKeyException;
7
use Apie\CompositeValueObjects\ValueObjectHashmapTrait;
8
use Apie\CompositeValueObjects\ValueObjectListInterface;
9
use Apie\OpenapiSchema\Spec\LinkObject;
10
use Apie\OpenapiSchema\Spec\Reference;
11
use Apie\TypeJuggling\AnotherValueObject;
12
use Apie\TypeJuggling\Compound;
13
use Apie\TypeJuggling\StringLiteral;
14
use Apie\TypeJuggling\TypeUtilInterface;
15
16
class LinkObjectMap implements ValueObjectListInterface
17
{
18
    use ValueObjectHashmapTrait;
19
20
    protected static function getWantedType(string $fieldName): TypeUtilInterface
21
    {
22
        if (!preg_match('/^[a-zA-Z0-9\.\-_]+$/', $fieldName)) {
23
            throw new InvalidKeyException($fieldName, null);
24
        }
25
        return new Compound(
26
            $fieldName,
27
            new AnotherValueObject($fieldName, LinkObject::class),
28
            new AnotherValueObject($fieldName, Reference::class),
29
            new StringLiteral($fieldName)
30
        );
31
    }
32
}
33