Test Setup Failed
Push — main ( e03535...dde247 )
by Pieter
03:39
created

RequestBodyMap::getWantedType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 2
eloc 6
c 1
b 1
f 1
nc 2
nop 1
dl 0
loc 9
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\Reference;
10
use Apie\OpenapiSchema\Spec\RequestBody;
11
use Apie\TypeJuggling\AnotherValueObject;
12
use Apie\TypeJuggling\Compound;
13
use Apie\TypeJuggling\TypeUtilInterface;
14
15
class RequestBodyMap implements ValueObjectListInterface
16
{
17
    use ValueObjectHashmapTrait;
18
19
    protected static function getWantedType(string $fieldName): TypeUtilInterface
20
    {
21
        if (!preg_match('/^[a-zA-Z0-9\.\-_]+$/', $fieldName)) {
22
            throw new InvalidKeyException($fieldName, null);
23
        }
24
        return new Compound(
25
            $fieldName,
26
            new AnotherValueObject($fieldName, RequestBody::class),
27
            new AnotherValueObject($fieldName, Reference::class)
28
        );
29
    }
30
}
31