Membership   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 120
ccs 12
cts 18
cp 0.6667
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getFromDate() 0 4 1
A setFromDate() 0 6 1
A getToDate() 0 4 1
A setToDate() 0 6 1
A getMember() 0 4 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\GetMemberInterface;
16
use App\Entity\Traits;
17
use Doctrine\ORM\Mapping as ORM;
18
use PascalDeVink\ShortUuid\ShortUuid;
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_memberships")
25
 * @OA\ApiResource(
26
 *   normalizationContext={"groups"={"get"}},
27
 *   itemOperations={
28
 *     "get"
29
 *   },
30
 *   collectionOperations={
31
 *     "get"
32
 *   }
33
 * )
34
 */
35
class Membership implements EntityInterface, GetMemberInterface
36
{
37
    use Traits\PropertyIdGeneratedTrait;
38
39
    /**
40
     * @var \DateTimeImmutable
41
     * @ORM\Column(name="from_date", type="date_immutable", nullable=false)
42
     *
43
     * @Assert\Date()
44
     *
45
     * @Serializer\Groups({"get"})
46
     * @OA\ApiProperty(
47
     *     attributes={
48
     *         "swagger_context"={"type"="string", "format"="date", "example"="2000-01-01"},
49
     *         "normalization_context"={"date_format"="Y-m-d", "datetime_format"="Y-m-d"},
50
     *     }
51
     * )
52
     * @OA\ApiFilter(
53
     *     ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::class,
54
     *     strategy="ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_BEFORE"
55
     * )
56
     * @OA\ApiFilter(
57
     *     ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class,
58
     *     strategy="exact"
59
     * )
60
     */
61
    private $fromDate;
62
63
    /**
64
     * @var \DateTimeImmutable
65
     * @ORM\Column(name="to_date", type="date_immutable", nullable=false)
66
     *
67
     * @Assert\Date()
68
     *
69
     * @Serializer\Groups({"get"})
70
     * @OA\ApiProperty(
71
     *     attributes={
72
     *         "swagger_context"={"type"="string", "format"="date", "example"="2000-01-01"},
73
     *         "normalization_context"={"date_format"="Y-m-d", "datetime_format"="Y-m-d"},
74
     *     }
75
     * )
76
     * @OA\ApiFilter(
77
     *     ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::class,
78
     *     strategy="ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_BEFORE"
79
     * )
80
     * @OA\ApiFilter(
81
     *     ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class,
82
     *     strategy="exact"
83
     * )
84
     */
85
    private $toDate;
86
87
    //-------------------------------------------------------------------------------------------
88
89
    /**
90
     * @var Member
91
     * @ORM\ManyToOne(targetEntity="App\Entity\Parking\Member", inversedBy="memberships")
92
     * @ORM\JoinColumn(name="member_id", referencedColumnName="id")
93
     *
94
     * @Assert\NotNull()
95
     *
96
     * @Serializer\Groups({"get"})
97
     * @OA\ApiProperty()
98
     * @OA\ApiSubresource(maxDepth=1)
99
     * @OA\ApiFilter(
100
     *     ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class,
101
     *     strategy="exact"
102
     * )
103
     * @OA\ApiFilter(
104
     *     ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter::class,
105
     *     strategy="exact",
106
     *     properties={"member.id"}
107
     * )
108
     */
109
    private $member;
110
111
    //-------------------------------------------------------------------------------------------
112
113 1
    public function __construct(
114
        Member $member,
115
        \DateTimeImmutable $fromDate,
116
        \DateTimeImmutable $toDate
117
    ) {
118 1
        $this->id = ShortUuid::uuid4();
119 1
        $this->member = $member;
120 1
        $this->setFromDate($fromDate);
121 1
        $this->setToDate($toDate);
122 1
    }
123
124
    //-------------------------------------------------------------------------------------------
125
126
    public function getFromDate(): ?\DateTimeImmutable
127
    {
128
        return $this->fromDate;
129
    }
130
131 1
    public function setFromDate(\DateTimeImmutable $fromDate): self
132
    {
133 1
        $this->fromDate = $fromDate;
134
135 1
        return $this;
136
    }
137
138
    public function getToDate(): ?\DateTimeImmutable
139
    {
140
        return $this->toDate;
141
    }
142
143 1
    public function setToDate(\DateTimeImmutable $toDate): self
144
    {
145 1
        $this->toDate = $toDate;
146
147 1
        return $this;
148
    }
149
150
    public function getMember(): Member
151
    {
152
        return $this->member;
153
    }
154
}
155