Completed
Push — master ( d7020d...a4700d )
by Daniel
06:50
created

FileDataTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
c 0
b 0
f 0
dl 0
loc 23
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedServices() 0 4 1
A supportsTransformation() 0 3 1
A transform() 0 7 1
1
<?php
2
3
namespace Silverback\ApiComponentBundle\DataTransformer;
4
5
use Silverback\ApiComponentBundle\Entity\Component\FileInterface;
6
use Silverback\ApiComponentBundle\Factory\FileDataFactory;
7
8
final class FileDataTransformer extends AbstractDataTransformer
9
{
10
    /**
11
     * @param FileInterface $object
12
     */
13
    public function transform($object, array $context = []): FileInterface
14
    {
15
        /** @var FileDataFactory $factory */
16
        $factory = $this->container->get(FileDataFactory::class);
17
        $fileData = $factory->create($object);
18
        $object->setFileData($fileData);
19
        return $object;
20
    }
21
22
    public function supportsTransformation($data, array $context = []): bool
23
    {
24
        return $data instanceof FileInterface;
25
    }
26
27
    public static function getSubscribedServices(): array
28
    {
29
        return [
30
            '?' . FileDataFactory::class
31
        ];
32
    }
33
}
34