AvailabilityBreak::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the zibios/sharep.
7
 *
8
 * (c) Zbigniew Ślązak
9
 */
10
11
namespace App\Entity\Parking;
12
13
use ApiPlatform\Core\Annotation as OA;
14
use App\Entity\EntityInterface;
15
use App\Entity\Traits;
16
use Doctrine\ORM\Mapping as ORM;
17
use PascalDeVink\ShortUuid\ShortUuid;
18
use Symfony\Bridge\Doctrine\Validator\Constraints as OrmAssert;
19
use Symfony\Component\Serializer\Annotation as Serializer;
20
use Symfony\Component\Validator\Constraints as Assert;
21
22
/**
23
 * @ORM\Entity()
24
 * @ORM\Table(name="parking_availability_breaks")
25
 * @OrmAssert\UniqueEntity(fields={"date"}, errorPath="date", message="Date already exist")
26
 * @OA\ApiResource(
27
 *   normalizationContext={"groups"={"get"}},
28
 *   itemOperations={
29
 *     "get"={
30
 *       "access_control"="is_granted('PARKING_AVAILABILITY_BREAK_READ')"
31
 *     },
32
 *     "delete"={
33
 *       "access_control"="is_granted('PARKING_AVAILABILITY_BREAK_DELETE', object)"
34
 *     },
35
 *     "put"={
36
 *       "denormalization_context"={"groups"={"put"}},
37
 *       "access_control"="is_granted('PARKING_AVAILABILITY_BREAK_UPDATE', object) and is_granted('PARKING_AVAILABILITY_BREAK_UPDATE', previous_object)"
38
 *     }
39
 *   },
40
 *   collectionOperations={
41
 *     "get"={
42
 *       "access_control"="is_granted('PARKING_AVAILABILITY_BREAK_READ')"
43
 *     },
44
 *     "post"={
45
 *       "denormalization_context"={"groups"={"post"}},
46
 *       "access_control"="is_granted('PARKING_AVAILABILITY_BREAK_CREATE', object)"
47
 *     }
48
 *   }
49
 * )
50
 */
51
class AvailabilityBreak implements EntityInterface
52
{
53
    use Traits\PropertyIdGeneratedTrait;
54
55
    /**
56
     * @var int
57
     * @ORM\Column(name="places", type="integer", nullable=false)
58
     *
59
     * @Assert\PositiveOrZero()
60
     *
61
     * @Serializer\Groups({"get", "put", "post"})
62
     * @OA\ApiFilter(
63
     *     ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\RangeFilter::class
64
     * )
65
     * @OA\ApiFilter(
66
     *     ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class,
67
     *     strategy="exact"
68
     * )
69
     */
70
    private $places;
71
72
    /**
73
     * @var string
74
     * @ORM\Column(name="reason", type="string", length=255, nullable=false)
75
     *
76
     * @Assert\NotBlank()
77
     * @Assert\Length(min="1", max="255")
78
     *
79
     * @Serializer\Groups({"get", "put", "post"})
80
     * @OA\ApiFilter(
81
     *     ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class,
82
     *     strategy="partial"
83
     * )
84
     */
85
    private $reason;
86
87
    /**
88
     * @var \DateTimeImmutable
89
     * @ORM\Column(name="date", type="date_immutable", nullable=false, unique=true)
90
     *
91
     * @Assert\Date()
92
     *
93
     * @Serializer\Groups({"get", "put", "post"})
94
     * @OA\ApiProperty(
95
     *     attributes={
96
     *         "swagger_context"={"type"="string", "format"="date_immutable", "example"="2000-01-01"},
97
     *         "normalization_context"={"date_format"="Y-m-d", "datetime_format"="Y-m-d"},
98
     *     }
99
     * )
100
     * @OA\ApiFilter(
101
     *     ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::class,
102
     *     strategy="ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_BEFORE"
103
     * )
104
     * @OA\ApiFilter(
105
     *     ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class,
106
     *     strategy="exact"
107
     * )
108
     */
109
    private $date;
110
111
    //-------------------------------------------------------------------------------------------
112
113 3
    public function __construct(
114
        int $places,
115
        string $reason,
116
        \DateTimeImmutable $date
117
    ) {
118 3
        $this->id = ShortUuid::uuid4();
119 3
        $this->setPlaces($places);
120 3
        $this->setReason($reason);
121 3
        $this->setDate($date);
122 3
    }
123
124
    //-------------------------------------------------------------------------------------------
125
126 3
    public function getPlaces(): int
127
    {
128 3
        return $this->places;
129
    }
130
131 3
    public function setPlaces(int $places): self
132
    {
133 3
        $this->places = $places;
134
135 3
        return $this;
136
    }
137
138 2
    public function getReason(): string
139
    {
140 2
        return $this->reason;
141
    }
142
143 3
    public function setReason(string $reason): self
144
    {
145 3
        $this->reason = $reason;
146
147 3
        return $this;
148
    }
149
150 2
    public function getDate(): \DateTimeImmutable
151
    {
152 2
        return $this->date;
153
    }
154
155 3
    public function setDate(\DateTimeImmutable $date): self
156
    {
157 3
        $this->date = $date;
158
159 3
        return $this;
160
    }
161
}
162