Passed
Branch feature/frontend (e3270d)
by Stone
12:41 queued 30s
created

Image   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 143
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 15
eloc 30
dl 0
loc 143
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpdatedAt() 0 5 1
A setTitle() 0 5 1
A getTitle() 0 3 1
A setImage() 0 5 1
A getImage() 0 3 1
A getPrimaryImage() 0 3 1
A setImageFile() 0 6 1
A getWebImage() 0 3 1
A setPrimaryImage() 0 5 1
A __toString() 0 3 1
A getId() 0 3 1
A getUpdatedAt() 0 3 1
A getImageFile() 0 3 1
1
<?php
2
3
namespace App\Entity;
4
5
use DateTimeImmutable;
6
use DateTimeInterface;
7
use Doctrine\ORM\Mapping as ORM;
8
use Exception;
9
use Symfony\Component\HttpFoundation\File\File;
10
use Symfony\Component\Validator\Constraints as Assert;
11
use Vich\UploaderBundle\Mapping\Annotation as Vich;
12
use Gedmo\Mapping\Annotation as Gedmo;
13
14
/**
15
 * @ORM\Entity(repositoryClass="App\Repository\ImageRepository")
16
 * @Vich\Uploadable
17
 */
18
class Image extends AbstractAppEntity
19
{
20
21
    /**
22
     * @ORM\Id()
23
     * @ORM\GeneratedValue()
24
     * @ORM\Column(type="integer")
25
     */
26
    private $id;
27
28
    /**
29
     * @ORM\Column(type="string", length=255, nullable=false)
30
     * @Assert\Length(
31
     *     min=5,
32
     *     max=255,
33
     *     minMessage = "Title must be at least {{ limit }} characters",
34
     *     maxMessage = "Title can not exceed {{ limit }} characters"
35
     * )
36
     */
37
    private $title;
38
39
    /**
40
     * @ORM\Column(type="string", length=255)
41
     */
42
    private $image;
43
44
    /**
45
     * @Vich\UploadableField(mapping="trick_images", fileNameProperty="image")
46
     * @var File
47
     */
48
    private $imageFile;
49
50
    /**
51
     * @ORM\ManyToOne(targetEntity="App\Entity\Trick", inversedBy="images")
52
     */
53
    private $trick;
54
55
    /**
56
     * @ORM\Column(type="datetime")
57
     * @Gedmo\Timestampable(on="update")
58
     */
59
    private $updatedAt;
60
61
    /**
62
     * @ORM\Column(type="boolean")
63
     */
64
    private $primaryImage = false;
65
66
    public function getId(): ?int
67
    {
68
        return $this->id;
69
    }
70
71
    public function getTitle(): ?string
72
    {
73
        return $this->title;
74
    }
75
76
    public function setTitle(?string $title): self
77
    {
78
        $this->title = $title;
79
80
        return $this;
81
    }
82
83
    public function getImage(): ?string
84
    {
85
        return $this->image;
86
    }
87
88
    public function getWebImage(): ?string
89
    {
90
        return '/uploads/trick_images/'.$this->image;
91
    }
92
93
94
    public function setImage(?string $image): self
95
    {
96
        $this->image = $image;
97
98
        return $this;
99
    }
100
101
    public function getTrick(): ?Trick
102
    {
103
        return $this->trick;
104
    }
105
106
    public function setTrick(?Trick $trick): self
107
    {
108
        $this->trick = $trick;
109
110
        return $this;
111
    }
112
113
    public function getUpdatedAt(): ?DateTimeInterface
114
    {
115
        return $this->updatedAt;
116
    }
117
118
    public function setUpdatedAt(DateTimeInterface $updatedAt): self
119
    {
120
        $this->updatedAt = $updatedAt;
121
122
        return $this;
123
    }
124
125
    /**
126
     * @return null|File
127
     */
128
    public function getImageFile(): ?File
129
    {
130
        return $this->imageFile;
131
    }
132
133
    /**
134
     * @param File $imageFile
135
     * @return Image
136
     * @throws Exception
137
     */
138
    public function setImageFile(File $imageFile): Image
139
    {
140
        $this->imageFile = $imageFile;
141
        $this->updatedAt = new DateTimeImmutable();
142
143
        return $this;
144
    }
145
146
    public function __toString()
147
    {
148
        return $this->getTitle();
149
    }
150
151
    public function getPrimaryImage(): ?bool
152
    {
153
        return $this->primaryImage;
154
    }
155
156
    public function setPrimaryImage(bool $primaryImage): self
157
    {
158
        $this->primaryImage = $primaryImage;
159
160
        return $this;
161
    }
162
}
163