ParameterList   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 14
c 2
b 1
f 1
dl 0
loc 24
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getWantedType() 0 6 1
A sanitizeValue() 0 11 4
1
<?php
2
3
4
namespace Apie\OpenapiSchema\Map;
5
6
use Apie\CompositeValueObjects\ValueObjectListInterface;
7
use Apie\CompositeValueObjects\ValueObjectListTrait;
8
use Apie\OpenapiSchema\Exceptions\DuplicateParameterInParameterList;
9
use Apie\OpenapiSchema\Spec\Parameter;
10
use Apie\OpenapiSchema\Spec\Reference;
11
use Apie\TypeJuggling\AnotherValueObject;
12
use Apie\TypeJuggling\Compound;
13
use Apie\TypeJuggling\TypeUtilInterface;
14
15
class ParameterList implements ValueObjectListInterface
16
{
17
    use ValueObjectListTrait;
18
19
    protected static function getWantedType(string $key): TypeUtilInterface
20
    {
21
        return new Compound(
22
            $key,
23
            new AnotherValueObject($key, Parameter::class),
24
            new AnotherValueObject($key, Reference::class)
25
        );
26
    }
27
28
    protected function sanitizeValue(): void
29
    {
30
        $seen = [];
31
        foreach ($this->list as $item) {
32
            if ($item instanceof Parameter) {
33
                $name = $item->getName();
34
                $in = $item->getIn()->toNative();
35
                if (!empty($seen[$name][$in])) {
36
                    throw new DuplicateParameterInParameterList($name, Parameter::fromNative($in));
37
                }
38
                $seen[$name][$in] = true;
39
            }
40
        }
41
    }
42
}
43