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\Service\Parking; |
12
|
|
|
|
13
|
|
|
use App\Entity\Parking\Member; |
14
|
|
|
use App\Entity\Parking\Reservation; |
15
|
|
|
use App\Enum\Entity\ReservationTypeEnum; |
16
|
|
|
use App\Enum\Functional\PermissionEnum; |
17
|
|
|
use App\Repository\Entity\Parking\ReservationRepository; |
18
|
|
|
use App\Traits\AssertTrait; |
19
|
|
|
use Symfony\Component\Security\Core\Security; |
20
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
21
|
|
|
|
22
|
|
|
class ReservationService |
23
|
|
|
{ |
24
|
|
|
use AssertTrait; |
25
|
|
|
|
26
|
|
|
/** @var ReservationRepository */ |
27
|
|
|
private $reservationRepository; |
28
|
|
|
/** @var ValidatorInterface */ |
29
|
|
|
private $validator; |
30
|
|
|
/** @var Security */ |
31
|
|
|
private $security; |
32
|
|
|
|
33
|
1 |
|
public function __construct(ReservationRepository $reservationRepository, ValidatorInterface $validator, Security $security) |
34
|
|
|
{ |
35
|
1 |
|
$this->reservationRepository = $reservationRepository; |
36
|
1 |
|
$this->validator = $validator; |
37
|
1 |
|
$this->security = $security; |
38
|
1 |
|
} |
39
|
|
|
|
40
|
|
|
public function updateReservation( |
41
|
|
|
Reservation $reservation, |
42
|
|
|
int $places, |
43
|
|
|
ReservationTypeEnum $reservationTypeEnum |
44
|
|
|
): Reservation { |
45
|
|
|
$reservation->setPlaces($places); |
46
|
|
|
$reservation->setType($reservationTypeEnum); |
47
|
|
|
$this->assertIsValidObject($this->validator, $reservation); |
|
|
|
|
48
|
|
|
$this->assertIsGranted($this->security, PermissionEnum::PARKING_RESERVATION_UPDATE, $reservation); |
|
|
|
|
49
|
|
|
|
50
|
|
|
$this->reservationRepository->saveAll($reservation); |
51
|
|
|
|
52
|
|
|
return $reservation; |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
public function createReservation( |
56
|
|
|
Member $member, |
57
|
|
|
\DateTimeImmutable $date, |
58
|
|
|
int $places, |
59
|
|
|
ReservationTypeEnum $reservationTypeEnum |
60
|
|
|
): Reservation { |
61
|
1 |
|
$reservation = new Reservation( |
62
|
1 |
|
$member, |
63
|
|
|
$date, |
64
|
|
|
$places, |
65
|
|
|
$reservationTypeEnum |
66
|
|
|
); |
67
|
1 |
|
$this->assertIsValidObject($this->validator, $reservation); |
|
|
|
|
68
|
1 |
|
$this->assertIsGranted($this->security, PermissionEnum::PARKING_RESERVATION_CREATE, $reservation); |
|
|
|
|
69
|
|
|
|
70
|
1 |
|
return $reservation; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function deleteReservation( |
74
|
|
|
Reservation $reservation |
75
|
|
|
): Reservation { |
76
|
|
|
$this->assertIsGranted($this->security, PermissionEnum::PARKING_RESERVATION_DELETE, $reservation); |
|
|
|
|
77
|
|
|
|
78
|
|
|
$this->reservationRepository->deleteAll($reservation); |
79
|
|
|
|
80
|
|
|
return $reservation; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: