Passed
Push — feature/uploadable ( 7c6d25...a7ed20 )
by Daniel
11:07
created

UploadableLoader::__construct()   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
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components 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\ApiComponentsBundle\Validator\MappingLoader;
15
16
use Silverback\ApiComponentsBundle\AnnotationReader\UploadableAnnotationReader;
17
use Symfony\Component\Validator\Constraints as Assert;
18
use Symfony\Component\Validator\Mapping\ClassMetadata;
19
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
20
21
/**
22
 * NOT CURRENTLY IN USE - NO LONGER NEED FOR UPLOADABLE BUT A GOOD REFERENCE FOR TIMESTAMPED WORK.
23
 *
24
 * @author Vincent Chalamon <[email protected]>
25
 */
26
final class UploadableLoader implements LoaderInterface
27
{
28
    private UploadableAnnotationReader $uploadsHelper;
29
30
    public function __construct(UploadableAnnotationReader $uploadsHelper)
31
    {
32
        $this->uploadsHelper = $uploadsHelper;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function loadClassMetadata(ClassMetadata $metadata): bool
39
    {
40
        if (!$this->uploadsHelper->isConfigured($metadata->getClassName())) {
41
            return false;
42
        }
43
44
        $fields = $this->uploadsHelper->getConfiguredProperties($metadata->getClassName(), true, false);
45
46
        foreach ($fields as $fileField) {
47
            $metadata->addPropertyConstraint($fileField, new Assert\NotNull(['groups' => sprintf('%s:create', $metadata->getClassName())]));
0 ignored issues
show
Bug introduced by
It seems like $fileField can also be of type Silverback\ApiComponents...otation\UploadableField; however, parameter $property of Symfony\Component\Valida...addPropertyConstraint() does only seem to accept string, 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

47
            $metadata->addPropertyConstraint(/** @scrutinizer ignore-type */ $fileField, new Assert\NotNull(['groups' => sprintf('%s:create', $metadata->getClassName())]));
Loading history...
48
        }
49
50
        return true;
51
    }
52
}
53