ResourceConverter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 38
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convert() 0 7 2
A getConverters() 0 3 1
A addConverter() 0 4 1
1
<?php
2
3
namespace kalanis\Restful\Converters;
4
5
6
/**
7
 * ResourceConverter
8
 * @package kalanis\Restful\Converters
9
 */
10
class ResourceConverter
11
{
12
13
    /** @var array<IConverter<string|int, mixed>> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<IConverter<string|int, mixed>> at position 2 could not be parsed: Expected '>' at position 2, but found 'IConverter'.
Loading history...
14
    private array $converters = [];
15
16
    /**
17
     * Get converters
18
     * @return array<IConverter<string|int, mixed>>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<IConverter<string|int, mixed>> at position 2 could not be parsed: Expected '>' at position 2, but found 'IConverter'.
Loading history...
19
     */
20
    public function getConverters(): array
21
    {
22
        return $this->converters;
23
    }
24
25
    /**
26
     * Add resource data converter to list
27
     * @param IConverter<string|int, mixed> $converter
28
     * @return $this
29
     */
30
    public function addConverter(IConverter $converter): self
31
    {
32 1
        $this->converters[] = $converter;
33 1
        return $this;
34
    }
35
36
    /**
37
     * Converts data from resource using converters
38
     * @param array<string|int, mixed> $data
39
     * @return array<string|int, mixed>
40
     */
41
    public function convert(array $data): array
42
    {
43 1
        foreach ($this->converters as $converter) {
44 1
            $data = $converter->convert($data);
45
        }
46
47 1
        return $data;
48
    }
49
}
50