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

UploadsLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 1
cc 1
nc 1
nop 1
crap 1
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