1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Application\Traits; |
||
6 | |||
7 | use Application\Model\Product; |
||
8 | use Application\Repository\ProductRepository; |
||
9 | use Doctrine\ORM\Mapping as ORM; |
||
10 | use GraphQL\Doctrine\Attribute as API; |
||
11 | use InvalidArgumentException; |
||
12 | |||
13 | trait HasSubscriptionLastReview |
||
14 | { |
||
15 | #[ORM\JoinColumn(onDelete: 'SET NULL')] |
||
16 | #[ORM\ManyToOne(targetEntity: Product::class)] |
||
17 | private ?Product $subscriptionLastReview = null; |
||
18 | |||
19 | /** |
||
20 | * Get last review number available through a subscription, bypassing all ACL so it also work even if review is not active yet. |
||
21 | */ |
||
22 | 2 | public function getSubscriptionLastReviewNumber(): ?int |
|
23 | { |
||
24 | /** @var ProductRepository $productRepository */ |
||
25 | 2 | $productRepository = _em()->getRepository(Product::class); |
|
26 | |||
27 | 2 | return $productRepository->getSubscriptionLastReviewNumber($this); |
|
28 | } |
||
29 | |||
30 | /** |
||
31 | * Set last review available through a subscription. |
||
32 | */ |
||
33 | #[API\Exclude] |
||
34 | public function setSubscriptionLastReview(?Product $subscriptionLastReview): void |
||
35 | { |
||
36 | if ($subscriptionLastReview && !$subscriptionLastReview->getReviewNumber()) { |
||
0 ignored issues
–
show
|
|||
37 | throw new InvalidArgumentException('The last review of a subscription must be a review, not an article'); |
||
38 | } |
||
39 | |||
40 | $this->subscriptionLastReview = $subscriptionLastReview; |
||
41 | } |
||
42 | } |
||
43 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: