Completed
Push — master ( 0be8e1...585ca2 )
by Daniel
59:26 queued 46:02
created

GalleryItem   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 47.83%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 80
ccs 11
cts 23
cp 0.4783
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 3 1
A __construct() 0 3 1
A setTitle() 0 4 1
A getCaption() 0 3 1
A setCaption() 0 4 1
A loadValidatorMetadata() 0 9 1
A getDir() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Silverback\ApiComponentBundle\Entity\Component\Gallery;
6
7
use Doctrine\ORM\Mapping as ORM;
8
use Silverback\ApiComponentBundle\Entity\Component\AbstractComponent;
9
use Silverback\ApiComponentBundle\Entity\Component\FileInterface;
10
use Silverback\ApiComponentBundle\Entity\Component\FileTrait;
11
use Symfony\Component\Serializer\Annotation\Groups;
12
use Symfony\Component\Validator\Constraints as Assert;
13
use Symfony\Component\Validator\Mapping\ClassMetadata;
14
15
/**
16
 * Class GalleryItem
17
 * @package Silverback\ApiComponentBundle\Entity\Component\Gallery
18
 * @author Daniel West <[email protected]>
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 1
    public static function loadValidatorMetadata(ClassMetadata $metadata)
43
    {
44 1
        $metadata->addPropertyConstraints(
45 1
            'filePath',
46 1
            [new Assert\Image()] // new Assert\NotBlank(),
47
        );
48 1
        $metadata->addPropertyConstraint(
49 1
            'title',
50 1
            new Assert\NotBlank()
51
        );
52 1
    }
53
54
    /**
55
     * Gallery constructor.
56
     */
57 2
    public function __construct()
58
    {
59 2
        parent::__construct();
60 2
    }
61
62
    /**
63
     * @return null|string
64
     */
65
    public function getTitle(): ?string
66
    {
67
        return $this->title;
68
    }
69
70
    /**
71
     * @param null|string $title
72
     * @return GalleryItem
73
     */
74
    public function setTitle(?string $title): self
75
    {
76
        $this->title = $title;
77
        return $this;
78
    }
79
80
    /**
81
     * @return null|string
82
     */
83
    public function getCaption(): ?string
84
    {
85
        return $this->caption;
86
    }
87
88
    /**
89
     * @param null|string $caption
90
     * @return GalleryItem
91
     */
92
    public function setCaption(?string $caption): self
93
    {
94
        $this->caption = $caption;
95
        return $this;
96
    }
97
98
    public function getDir(): ?string
99
    {
100
        return 'gallery';
101
    }
102
}
103