Page   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 26
ccs 0
cts 5
cp 0
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A loadValidatorMetadata() 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\Doctrine\Orm\Filter\OrderFilter;
17
use ApiPlatform\Metadata\ApiFilter;
18
use ApiPlatform\Metadata\ApiResource;
19
use Silverback\ApiComponentsBundle\Entity\Utility\UiTrait;
20
use Silverback\ApiComponentsBundle\Filter\OrSearchFilter;
21
use Symfony\Component\Serializer\Annotation\Groups;
22
use Symfony\Component\Validator\Constraints as Assert;
23
use Symfony\Component\Validator\Mapping\ClassMetadata;
24
25
/**
26
 * @author Daniel West <[email protected]>
27
 */
28
#[ApiResource(mercure: true)]
29
#[ApiFilter(OrderFilter::class, properties: ['createdAt', 'reference'], arguments: ['orderParameterName' => 'order'])]
30
#[ApiFilter(OrSearchFilter::class, properties: ['title' => 'ipartial', 'reference' => 'ipartial', 'isTemplate' => 'exact', 'uiComponent' => 'ipartial', 'layout.reference' => 'ipartial'])]
31
class Page extends AbstractPage
32
{
33
    use UiTrait;
34
35
    #[Assert\NotBlank(message: 'Please specify a layout.')]
36
    #[Groups(['Route:manifest:read'])]
37
    public ?Layout $layout;
38
39
    #[Assert\NotBlank(message: 'Please enter a reference.')]
40
    public string $reference;
41
42
    #[Assert\NotNull(message: 'Please specify if this page is a template or not.')]
43
    public bool $isTemplate;
44
45
    public function __construct()
46
    {
47
        $this->initComponentGroups();
48
    }
49
50
    public static function loadValidatorMetadata(ClassMetadata $metadata): void
51
    {
52
        $metadata->addPropertyConstraint('uiComponent', new Assert\NotBlank([
53
            'message' => 'Please specify a UI component.',
54
        ]));
55
    }
56
}
57