Passed
Push — develop ( e7301d...771d14 )
by Daniel
05:36
created

Hero::setTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Entity\Content\Component\Hero;
4
5
use ApiPlatform\Core\Annotation\ApiResource;
6
use Doctrine\ORM\Mapping as ORM;
7
use Silverback\ApiComponentBundle\Entity\Content\Component\AbstractComponent;
8
use Silverback\ApiComponentBundle\Entity\Content\Component\Navigation\Tabs\Tabs;
9
use Silverback\ApiComponentBundle\Entity\Content\ComponentGroup;
10
use Silverback\ApiComponentBundle\Entity\Content\FileInterface;
11
use Silverback\ApiComponentBundle\Entity\Content\FileTrait;
12
use Symfony\Component\Serializer\Annotation\Groups;
13
use Symfony\Component\Validator\Constraints as Assert;
14
use Symfony\Component\Validator\Mapping\ClassMetadata;
15
16
/**
17
 * Class Hero
18
 * @package Silverback\ApiComponentBundle\Entity\Content\Component\Hero
19
 * @author Daniel West <[email protected]>
20
 * @ApiResource()
21
 * @ORM\Entity()
22
 */
23
class Hero extends AbstractComponent implements FileInterface
24
{
25
    use FileTrait;
26
27
    /**
28
     * @ORM\Column(type="string", nullable=false)
29
     * @Groups({"content", "component"})
30
     * @var null|string
31
     */
32
    private $title;
33
34
    /**
35
     * @ORM\Column(type="string")
36
     * @Groups({"content", "component"})
37
     * @var null|string
38
     */
39
    private $subtitle;
40
41 3
    public function __construct()
42
    {
43 3
        parent::__construct();
44 3
        $this->addValidComponent(Tabs::class);
45 3
        $this->addComponentGroup(new ComponentGroup());
46 3
    }
47
48 6
    public static function loadValidatorMetadata(ClassMetadata $metadata)
49
    {
50 6
        $metadata->addPropertyConstraint(
51 6
            'title',
52 6
            new Assert\NotNull()
53
        );
54 6
        $metadata->addPropertyConstraint(
55 6
            'filePath',
56 6
            new Assert\Image()
57
        );
58 6
    }
59
60
    /**
61
     * @return null|string
62
     */
63 1
    public function getTitle(): ?string
64
    {
65 1
        return $this->title;
66
    }
67
68
    /**
69
     * @param null|string $title
70
     */
71 2
    public function setTitle(?string $title): void
72
    {
73 2
        $this->title = $title;
74 2
    }
75
76
    /**
77
     * @return null|string
78
     */
79 1
    public function getSubtitle(): ?string
80
    {
81 1
        return $this->subtitle;
82
    }
83
84
    /**
85
     * @param null|string $subtitle
86
     */
87 2
    public function setSubtitle(?string $subtitle): void
88
    {
89 2
        $this->subtitle = $subtitle;
90 2
    }
91
92
    public function __toString()
93
    {
94
        return 'Hero: ' . $this->getTitle();
95
    }
96
}
97