Test Failed
Push — develop ( 92c10d...ff12cf )
by Daniel
05:05
created

DynamicPage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 46
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 2
A getDynamicPageClass() 0 3 1
A getSortCollection() 0 3 1
A setDynamicPageClass() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Silverback\ApiComponentBundle\Entity\Content\Page;
6
7
use Doctrine\Common\Collections\Collection;
8
use Doctrine\ORM\Mapping as ORM;
9
use Silverback\ApiComponentBundle\Entity\Route\ChildRouteInterface;
10
use Silverback\ApiComponentBundle\Entity\Route\ChildRouteTrait;
11
use Silverback\ApiComponentBundle\Entity\SortableInterface;
12
use Silverback\ApiComponentBundle\Entity\SortableTrait;
13
use Symfony\Component\Serializer\Annotation\Groups;
14
use Symfony\Component\Validator\Constraints as Assert;
15
use Symfony\Component\Validator\Context\ExecutionContextInterface;
16
17
/**
18
 * @ORM\Entity()
19
 */
20
class DynamicPage extends AbstractPage implements SortableInterface, ChildRouteInterface
21
{
22
    use SortableTrait;
23
    use ChildRouteTrait;
24
25
    /**
26
     * Groups differ from page
27
     * @Groups({"dynamic_content", "route"})
28
     */
29
    protected $componentLocations;
30
31
    /**
32
     * @ORM\Column(type="string", nullable=true)
33
     * @Groups({"component_write"})
34
     * @var null|string
35
     */
36
    protected $dynamicPageClass;
37
38
    protected $dynamic = true;
39
40
    public function getDynamicPageClass(): ?string
41
    {
42
        return $this->dynamicPageClass;
43
    }
44
45
    public function setDynamicPageClass(?string $dynamicPageClass): self
46
    {
47
        $this->dynamicPageClass = $dynamicPageClass;
48
        return $this;
49
    }
50
51
    public function getSortCollection(): ?Collection
52
    {
53
        return null;
54
    }
55
56
57
    /**
58
     * @Assert\Callback()
59
     */
60
    public function validate(ExecutionContextInterface $context): void
61
    {
62
        if (!$this->getDynamicPageClass()) {
63
            $context->buildViolation('The content is required if dynamicPageClass is not provided')
64
                ->atPath('content')
65
                ->addViolation();
66
        }
67
    }
68
}
69