Passed
Pull Request — main (#146)
by Daniel
07:02 queued 02:35
created

ComponentPosition::setComponentCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
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 1
dl 0
loc 5
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\Metadata\ApiResource;
17
use Doctrine\Common\Collections\Collection;
18
use Silverback\ApiComponentsBundle\Annotation as Silverback;
19
use Silverback\ApiComponentsBundle\Entity\Utility\IdTrait;
20
use Silverback\ApiComponentsBundle\Entity\Utility\TimestampedTrait;
21
use Silverback\ApiComponentsBundle\Validator\Constraints as AcbAssert;
22
use Symfony\Component\Serializer\Annotation\Groups;
23
use Symfony\Component\Validator\Constraints as Assert;
24
25
/**
26
 * @author Daniel West <[email protected]>
27
 */
28
#[Silverback\Timestamped]
29
#[ApiResource(mercure: true, order: ['sortValue' => 'ASC'])]
30
#[AcbAssert\ComponentPosition]
31
#[Assert\Expression(
32
    '!(this.component == null & this.pageDataProperty == null)',
33
    message: 'Please specify either a component or pageDataProperty.',
34
)]
35
class ComponentPosition
36
{
37
    use IdTrait;
38
    use TimestampedTrait;
39
40
    #[Assert\NotNull]
41
    #[Groups(['ComponentPosition:read', 'ComponentPosition:write', 'AbstractComponent:cwa_resource:write'])]
42
    public ?ComponentGroup $componentGroup = null;
43
44
    #[Groups(['ComponentPosition:read', 'ComponentPosition:write'])]
45
    public ?AbstractComponent $component = null;
46
47
    #[Groups(['ComponentPosition:read:role_admin', 'ComponentPosition:write'])]
48
    public ?string $pageDataProperty = null;
49
50
    #[Assert\NotNull]
51
    #[Groups(['ComponentPosition:read', 'ComponentPosition:write'])]
52
    public ?int $sortValue = null;
53
54
    /**
55
     * @return ComponentPosition[]|Collection|null
56
     */
57
    public function getSortCollection(): ?Collection
58
    {
59
        return $this->componentGroup ? $this->componentGroup->componentPositions : null;
60
    }
61
62
    public function setComponentGroup(ComponentGroup $componentGroup): self
63
    {
64
        $this->componentGroup = $componentGroup;
65
66
        return $this;
67
    }
68
69
    public function setComponent(AbstractComponent $component): self
70
    {
71
        $this->component = $component;
72
73
        return $this;
74
    }
75
76
    public function setSortValue(int $sortValue): self
77
    {
78
        $this->sortValue = $sortValue;
79
80
        return $this;
81
    }
82
83
    public function getPageDataProperty(): ?string
84
    {
85
        return $this->pageDataProperty;
86
    }
87
88
    public function setPageDataProperty(?string $pageDataProperty): self
89
    {
90
        $this->pageDataProperty = $pageDataProperty;
91
92
        return $this;
93
    }
94
}
95