Passed
Push — master ( fe8874...312ccc )
by Paul
02:35
created

FormObjectTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 2
A transform() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CCT\Component\Rest\Transformer\Request;
6
7
class FormObjectTransformer extends AbstractSerializerRequestTransformer
8
{
9
10
    /**
11
     * {@inheritdoc}
12
     */
13
    public function transform($formData = []): array
14
    {
15
        if (empty($formData)) {
16
            return [];
17
        }
18
19
        if (is_object($formData)) {
20
            $formData = $this->serializer->toArray(
21
                $formData,
22
                $this->serializationContext
23
            );
24
        }
25
26
        return $formData;
27
    }
28
29
    /**
30
     * Checks if the formData is supported to execute the transformation.
31
     *
32
     * @param array|object $formData
33
     *
34
     * @return bool
35
     */
36
    public function supports($formData): bool
37
    {
38
        return is_object($formData) || is_array($formData);
39
    }
40
}
41