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

Form::loadValidatorMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
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\Entity\Component;
15
16
use ApiPlatform\Core\Annotation\ApiProperty;
17
use Doctrine\ORM\Mapping as ORM;
18
use Silverback\ApiComponentsBundle\Annotation as Silverback;
19
use Silverback\ApiComponentsBundle\Dto\FormView;
20
use Silverback\ApiComponentsBundle\Entity\Core\AbstractComponent;
21
use Silverback\ApiComponentsBundle\Entity\Utility\TimestampedTrait;
22
use Silverback\ApiComponentsBundle\Validator\Constraints as ACBAssert;
23
use Symfony\Component\Validator\Constraints as Assert;
24
use Symfony\Component\Validator\Mapping\ClassMetadata;
25
26
/**
27
 * @author Daniel West <[email protected]>
28
 *
29
 * @Silverback\Timestamped
30
 * @ORM\Entity
31
 */
32
class Form extends AbstractComponent
33
{
34
    use TimestampedTrait;
35
36
    /**
37
     * @ORM\Column(nullable=false)
38
     */
39
    public string $formType;
40
41
    /** @ApiProperty(writable=false) */
42
    public ?FormView $formView = null;
43
44
    public static function loadValidatorMetadata(ClassMetadata $metadata): void
45
    {
46
        $metadata->addPropertyConstraints(
47
            'formType',
48
            [
49
                new Assert\NotBlank(),
50
                new ACBAssert\FormTypeClass(),
51
            ]
52
        );
53
    }
54
}
55