| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Setono\SyliusLogEntryPlugin\Model; |
||
| 6 | |||
| 7 | use Doctrine\Common\Collections\ArrayCollection; |
||
| 8 | use Doctrine\Common\Collections\Collection; |
||
| 9 | |||
| 10 | trait LogEntriesAwareTrait |
||
| 11 | { |
||
| 12 | /** @var Collection|LogEntryInterface[] */ |
||
| 13 | protected $logEntries; |
||
| 14 | |||
| 15 | public function __construct() |
||
| 16 | { |
||
| 17 | $this->logEntries = new ArrayCollection(); |
||
| 18 | } |
||
| 19 | |||
| 20 | public function getLogEntries(): Collection |
||
| 21 | { |
||
| 22 | return $this->logEntries; |
||
| 23 | } |
||
| 24 | |||
| 25 | public function hasLogEntries(): bool |
||
| 26 | { |
||
| 27 | return !$this->logEntries->isEmpty(); |
||
| 28 | } |
||
| 29 | |||
| 30 | public function addLogEntry(LogEntryInterface $logEntry): void |
||
| 31 | { |
||
| 32 | if ($this->hasLogEntry($logEntry)) { |
||
| 33 | return; |
||
| 34 | } |
||
| 35 | |||
| 36 | $this->logEntries->add($logEntry); |
||
| 37 | $logEntry->setOwner($this); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 38 | } |
||
| 39 | |||
| 40 | public function removeLogEntry(LogEntryInterface $logEntry): void |
||
| 41 | { |
||
| 42 | if (!$this->hasLogEntry($logEntry)) { |
||
| 43 | return; |
||
| 44 | } |
||
| 45 | |||
| 46 | $this->logEntries->removeElement($logEntry); |
||
| 47 | $logEntry->setOwner(null); |
||
| 48 | } |
||
| 49 | |||
| 50 | public function hasLogEntry(LogEntryInterface $logEntry): bool |
||
| 51 | { |
||
| 52 | return $this->logEntries->contains($logEntry); |
||
| 53 | } |
||
| 54 | } |
||
| 55 |