Test Failed
Pull Request — master (#52)
by Vincent
10:09 queued 01:58
created

UploadsLoader   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 7
c 1
b 0
f 1
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A loadClassMetadata() 0 11 2
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\Validator\MappingLoader;
15
16
use Silverback\ApiComponentBundle\Annotation\Uploads;
17
use Silverback\ApiComponentBundle\Helper\UploadsHelper;
18
use Symfony\Component\Validator\Constraints as Assert;
19
use Symfony\Component\Validator\Mapping\ClassMetadata;
20
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
21
22
/**
23
 * @author Vincent Chalamon <[email protected]>
24
 */
25
final class UploadsLoader implements LoaderInterface
26
{
27
    private UploadsHelper $uploadsHelper;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function loadClassMetadata(ClassMetadata $metadata)
33
    {
34
        if (!$this->uploadsHelper->isConfigured($metadata->getClassName())) {
35
            return false;
36
        }
37
38
        /** @var Uploads $configuration */
39
        $configuration = $this->uploadsHelper->getConfiguration($metadata->getClassName());
40
        $metadata->addPropertyConstraint($configuration->fieldName, new Assert\NotNull());
41
42
        return true;
43
    }
44
}
45