Layout::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
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\Core;
15
16
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
17
use ApiPlatform\Metadata\ApiFilter;
18
use ApiPlatform\Metadata\ApiResource;
19
use Doctrine\Common\Collections\ArrayCollection;
20
use Doctrine\Common\Collections\Collection;
21
use Silverback\ApiComponentsBundle\Annotation as Silverback;
22
use Silverback\ApiComponentsBundle\Entity\Utility\IdTrait;
23
use Silverback\ApiComponentsBundle\Entity\Utility\TimestampedTrait;
24
use Silverback\ApiComponentsBundle\Entity\Utility\UiTrait;
25
use Silverback\ApiComponentsBundle\Filter\OrSearchFilter;
26
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
27
use Symfony\Component\Validator\Constraints as Assert;
28
use Symfony\Component\Validator\Mapping\ClassMetadata;
29
30
/**
31
 * @author Daniel West <[email protected]>
32
 */
33
#[Silverback\Timestamped]
34
#[ApiResource(mercure: true)]
35
#[ApiFilter(OrderFilter::class, properties: ['createdAt', 'reference'], arguments: ['orderParameterName' => 'order'])]
36
#[ApiFilter(OrSearchFilter::class, properties: ['reference' => 'ipartial', 'uiComponent' => 'ipartial'])]
37
#[UniqueEntity(fields: ['reference'], message: 'There is already a Layout with that reference.')]
38
class Layout
39
{
40
    use IdTrait;
41
    use TimestampedTrait;
42
    use UiTrait;
43
44
    #[Assert\NotBlank(message: 'Please enter a reference.')]
45
    public string $reference;
46
47
    /**
48
     * @var Collection|Page[]
49
     */
50
    public Collection $pages;
51
52
    public function __construct()
53
    {
54
        $this->initComponentGroups();
55
        $this->pages = new ArrayCollection();
56
    }
57
58
    public static function loadValidatorMetadata(ClassMetadata $metadata): void
59
    {
60
        $metadata->addPropertyConstraint('uiComponent', new Assert\NotBlank([
61
            'message' => 'You must define the uiComponent for this resource.',
62
        ]));
63
    }
64
}
65