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

FormObjectTransformer::transform()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 14
ccs 0
cts 8
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
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