Passed
Push — develop ( 0112d6...38c008 )
by Daniel
05:14
created

GalleryItem::getDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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