Passed
Push — master ( 3ec415...9f2f47 )
by Daniel
16:25
created

Layout   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 26
ccs 4
cts 7
cp 0.5714
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loadValidatorMetadata() 0 4 1
A __construct() 0 4 1
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\Core;
15
16
use ApiPlatform\Core\Annotation\ApiResource;
17
use Doctrine\Common\Collections\ArrayCollection;
18
use Doctrine\Common\Collections\Collection;
19
use Silverback\ApiComponentsBundle\Annotation as Silverback;
20
use Silverback\ApiComponentsBundle\Entity\Utility\IdTrait;
21
use Silverback\ApiComponentsBundle\Entity\Utility\TimestampedTrait;
22
use Silverback\ApiComponentsBundle\Entity\Utility\UiTrait;
23
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
24
use Symfony\Component\Validator\Constraints as Assert;
25
use Symfony\Component\Validator\Mapping\ClassMetadata;
26
27
/**
28
 * @author Daniel West <[email protected]>
29
 *
30
 * @Silverback\Timestamped
31
 * @ApiResource(mercure=true)
32
 * @UniqueEntity(fields={"reference"}, message="There is already a Layout with that reference.")
33
 */
34
class Layout
35
{
36
    use IdTrait;
37
    use TimestampedTrait;
38
    use UiTrait;
39
40
    /**
41
     * @Assert\NotBlank(message="Please enter a reference.")
42
     */
43
    public string $reference;
44
45
    /**
46
     * @var Collection|Page[]
47
     */
48
    public Collection $pages;
49
50 1
    public function __construct()
51
    {
52 1
        $this->initComponentCollections();
53 1
        $this->pages = new ArrayCollection();
54 1
    }
55
56
    public static function loadValidatorMetadata(ClassMetadata $metadata): void
57
    {
58
        $metadata->addPropertyConstraint('uiComponent', new Assert\NotBlank([
59
            'message' => 'You must define the uiComponent for this resource.',
60
        ]));
61
    }
62
}
63