Completed
Push — develop ( f21c4e...9941da )
by Daniel
10:22
created

GalleryItem::setCaption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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