Passed
Push — v2 ( e7f8e2...a41bff )
by Daniel
04:01
created

supportsTransformation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentBundle\DataTransformer;
15
16
use ApiPlatform\Core\DataTransformer\DataTransformerInterface;
17
use Silverback\ApiComponentBundle\Entity\Utility\FileInterface;
18
use Silverback\ApiComponentBundle\Factory\FileDataFactory;
19
20
/**
21
 * @author Daniel West <[email protected]>
22
 */
23
class FileOutputDataTransformer implements DataTransformerInterface
24
{
25
    private FileDataFactory $fileDataFactory;
26
27
    public function __construct(FileDataFactory $fileDataFactory)
28
    {
29
        $this->fileDataFactory = $fileDataFactory;
30
    }
31
32
    /**
33
     * @param FileInterface $object
34
     */
35
    public function transform($object, string $to, array $context = [])
36
    {
37
        $object->setFileData($this->fileDataFactory->create($object));
0 ignored issues
show
Bug introduced by
It seems like $this->fileDataFactory->create($object) can also be of type null; however, parameter $fileData of Silverback\ApiComponentB...nterface::setFileData() does only seem to accept Silverback\ApiComponentBundle\Dto\File\FileData, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        $object->setFileData(/** @scrutinizer ignore-type */ $this->fileDataFactory->create($object));
Loading history...
38
39
        return $object;
40
    }
41
42
    public function supportsTransformation($data, string $to, array $context = []): bool
43
    {
44
        return $data instanceof FileInterface;
45
    }
46
}
47