Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
22 / 22 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
| Deposit | |
100.00% |
22 / 22 |
|
100.00% |
11 / 11 |
16 | |
100.00% |
1 / 1 |
| getEntity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setEntity | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setDate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getDocument | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setDocument | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getAmount | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setAmount | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getTransaction | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setTransaction | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Entity; |
| 6 | |
| 7 | use App\Enum\PaymentMethodId; |
| 8 | use App\Repository\DepositRepository; |
| 9 | use DateTime; |
| 10 | use Doctrine\DBAL\Types\Types; |
| 11 | use Doctrine\ORM\Mapping\Column; |
| 12 | use Doctrine\ORM\Mapping\Entity; |
| 13 | use Doctrine\ORM\Mapping\GeneratedValue; |
| 14 | use Doctrine\ORM\Mapping\Id; |
| 15 | use Doctrine\ORM\Mapping\ManyToOne; |
| 16 | use Doctrine\ORM\Mapping\OneToOne; |
| 17 | use UnexpectedValueException; |
| 18 | |
| 19 | #[Entity(repositoryClass: DepositRepository::class)] |
| 20 | class Deposit |
| 21 | { |
| 22 | #[Column, Id, GeneratedValue] |
| 23 | private ?int $id = null; |
| 24 | |
| 25 | #[ManyToOne] |
| 26 | private PaymentMethod $entity; |
| 27 | |
| 28 | #[Column(type: Types::DATE_MUTABLE, nullable: false)] |
| 29 | private DateTime $date; |
| 30 | |
| 31 | #[Column(length: 150, nullable: false)] |
| 32 | private string $document; |
| 33 | |
| 34 | #[Column(type: Types::DECIMAL, precision: 13, scale: 2, nullable: false)] |
| 35 | private string $amount; |
| 36 | |
| 37 | #[OneToOne(targetEntity: Transaction::class, mappedBy: 'deposit', cascade: [ |
| 38 | 'persist', |
| 39 | 'remove', |
| 40 | ])] |
| 41 | private ?Transaction $transaction = null; |
| 42 | |
| 43 | public function getEntity(): PaymentMethod |
| 44 | { |
| 45 | return $this->entity; |
| 46 | } |
| 47 | |
| 48 | public function setEntity(PaymentMethod $entity): static |
| 49 | { |
| 50 | if (PaymentMethodId::BAR->value === $entity->getId()) { |
| 51 | throw new UnexpectedValueException('The entity with ID "1" is supposed to be the BAR payment method!'); |
| 52 | } |
| 53 | |
| 54 | $this->entity = $entity; |
| 55 | |
| 56 | return $this; |
| 57 | } |
| 58 | |
| 59 | public function getId(): ?int |
| 60 | { |
| 61 | return $this->id; |
| 62 | } |
| 63 | |
| 64 | public function getDate(): DateTime |
| 65 | { |
| 66 | return $this->date; |
| 67 | } |
| 68 | |
| 69 | public function setDate(DateTime $date): static |
| 70 | { |
| 71 | $this->date = $date; |
| 72 | |
| 73 | return $this; |
| 74 | } |
| 75 | |
| 76 | public function getDocument(): string |
| 77 | { |
| 78 | return $this->document; |
| 79 | } |
| 80 | |
| 81 | public function setDocument(string $document): static |
| 82 | { |
| 83 | $this->document = $document; |
| 84 | |
| 85 | return $this; |
| 86 | } |
| 87 | |
| 88 | public function getAmount(): string |
| 89 | { |
| 90 | return $this->amount; |
| 91 | } |
| 92 | |
| 93 | public function setAmount(string $amount): static |
| 94 | { |
| 95 | $this->amount = $amount; |
| 96 | |
| 97 | return $this; |
| 98 | } |
| 99 | |
| 100 | public function getTransaction(): ?Transaction |
| 101 | { |
| 102 | return $this->transaction; |
| 103 | } |
| 104 | |
| 105 | public function setTransaction(?Transaction $transaction): self |
| 106 | { |
| 107 | // unset the owning side of the relation if necessary |
| 108 | if (!$transaction instanceof Transaction && $this->transaction instanceof Transaction) { |
| 109 | $this->transaction->setDeposit(null); |
| 110 | } |
| 111 | |
| 112 | // set the owning side of the relation if necessary |
| 113 | if ($transaction instanceof Transaction && $transaction->getDeposit() !== $this) { |
| 114 | $transaction->setDeposit($this); |
| 115 | } |
| 116 | |
| 117 | $this->transaction = $transaction; |
| 118 | |
| 119 | return $this; |
| 120 | } |
| 121 | } |