Test Failed
Branch develop (ac2838)
by Daniel
09:09
created

GalleryItem   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 79
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A loadValidatorMetadata() 0 9 1
A getTitle() 0 3 1
A __construct() 0 4 1
A setTitle() 0 4 1
A getCaption() 0 3 1
A setCaption() 0 4 1
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Entity\Component\Gallery;
4
5
use ApiPlatform\Core\Annotation\ApiResource;
6
use Doctrine\Common\Collections\ArrayCollection;
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
 * @ApiResource(shortName="component/gallery_item")
20
 * @ORM\Entity()
21
 */
22
class GalleryItem extends AbstractComponent implements FileInterface
23
{
24
    use FileTrait;
25
26
    /**
27
     * @ORM\Column()
28
     * @Groups({"component", "content"})
29
     * @var null|string
30
     */
31
    protected $title;
32
33
    /**
34
     * @ORM\Column()
35
     * @Groups({"component", "content"})
36
     * @var null|string
37
     */
38
    protected $caption;
39
40
    /**
41
     * @param ClassMetadata $metadata
42
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
43
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
44
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
45
     */
46
    public static function loadValidatorMetadata(ClassMetadata $metadata)
47
    {
48
        $metadata->addPropertyConstraint(
49
            'filePath',
50
            new Assert\NotBlank()
51
        );
52
        $metadata->addPropertyConstraint(
53
            'title',
54
            new Assert\NotBlank()
55
        );
56
    }
57
58
    /**
59
     * Gallery constructor.
60
     */
61
    public function __construct()
62
    {
63
        parent::__construct();
64
        $this->routes = new ArrayCollection;
0 ignored issues
show
Bug Best Practice introduced by
The property routes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
65
    }
66
67
    /**
68
     * @return null|string
69
     */
70
    public function getTitle(): ?string
71
    {
72
        return $this->title;
73
    }
74
75
    /**
76
     * @param null|string $title
77
     * @return GalleryItem
78
     */
79
    public function setTitle(?string $title): self
80
    {
81
        $this->title = $title;
82
        return $this;
83
    }
84
85
    /**
86
     * @return null|string
87
     */
88
    public function getCaption(): ?string
89
    {
90
        return $this->caption;
91
    }
92
93
    /**
94
     * @param null|string $caption
95
     * @return GalleryItem
96
     */
97
    public function setCaption(?string $caption): self
98
    {
99
        $this->caption = $caption;
100
        return $this;
101
    }
102
}
103