Passed
Pull Request — master (#52)
by Vincent
08:41 queued 02:04
created

UploadsLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 8
dl 0
loc 23
ccs 3
cts 9
cp 0.3333
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
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 1
    public function __construct(UploadsHelper $uploadsHelper)
30
    {
31 1
        $this->uploadsHelper = $uploadsHelper;
32 1
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function loadClassMetadata(ClassMetadata $metadata)
38
    {
39
        if (!$this->uploadsHelper->isConfigured($metadata->getClassName())) {
40
            return false;
41
        }
42
43
        /** @var Uploads $configuration */
44
        $configuration = $this->uploadsHelper->getConfiguration($metadata->getClassName());
45
        $metadata->addPropertyConstraint($configuration->fieldName, new Assert\NotNull());
46
47
        return true;
48
    }
49
}
50