-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFundingWithdrawal.php
More file actions
98 lines (82 loc) · 2.75 KB
/
FundingWithdrawal.php
File metadata and controls
98 lines (82 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
declare(strict_types=1);
namespace MatchBot\Domain;
use Doctrine\ORM\Mapping as ORM;
/**
* @psalm-suppress PropertyNotSetInConstructor Not requiring all props on construct for now.
*/
#[ORM\Entity(repositoryClass: FundingWithdrawalRepository::class)]
#[ORM\HasLifecycleCallbacks]
class FundingWithdrawal extends Model
{
use TimestampsTrait;
/**
* @psalm-suppress PossiblyUnusedProperty - probably used in DB queries
*/
#[ORM\ManyToOne(targetEntity: Donation::class, inversedBy: 'fundingWithdrawals', fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: false)]
protected Donation $donation;
/**
* @var numeric-string Always use bcmath methods as in repository helpers to avoid doing float maths with decimals!
*/
#[ORM\Column(type: 'decimal', precision: 18, scale: 2)]
protected string $amount;
/**
* @var CampaignFunding
* phpstan error below ignored, consider migrating DB to make column non-null if possible.
*/
#[ORM\ManyToOne(targetEntity: CampaignFunding::class, fetch: 'EAGER', inversedBy: 'fundingWithdrawals')]
private readonly CampaignFunding $campaignFunding; // @phpstan-ignore doctrine.associationType
/**
* If non-null indicates that this FW has now been released (e.g. because the related inchoate donation expired or
* was cancelled), so is now of historical interest only and should not count towards current totals.
*/
#[ORM\Column(nullable: true)]
private(set) \DateTimeImmutable|null $releasedAt = null;
/**
* @param CampaignFunding $campaignFunding
* @param Donation $donation
* @param numeric-string $amount
*/
public function __construct(CampaignFunding $campaignFunding, Donation $donation, string $amount)
{
$this->campaignFunding = $campaignFunding;
$this->donation = $donation;
$this->amount = $amount;
$this->createdNow();
}
/**
* Ensure the parent Donation is marked updated whenever a withdrawal changes, so polling can rely on Donation only.
*
* @psalm-suppress PossiblyUnusedMethod - called by ORM
*/
#[ORM\PrePersist]
#[ORM\PreUpdate]
#[ORM\PreRemove]
public function touchParentDonation(): void
{
$this->donation->updatedNow();
}
/**
* @return numeric-string
*/
public function getAmount(): string
{
return $this->amount;
}
public function getCampaignFunding(): CampaignFunding
{
return $this->campaignFunding;
}
public function isReleased(): bool
{
return $this->releasedAt !== null;
}
public function release(\DateTimeImmutable $at): void
{
if ($this->releasedAt !== null) {
return;
}
$this->releasedAt = $at;
}
}