src/Entity/VirusScanItem.php line 14

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use MedBrief\MSR\Repository\VirusScanItemRepository;
  5. use MedBrief\MSR\Service\VirusScan\Async\VirusScannableInterface;
  6. /**
  7. * @ORM\Table(name="VirusScanItem")
  8. *
  9. * @ORM\Entity(repositoryClass=VirusScanItemRepository::class)
  10. */
  11. class VirusScanItem
  12. {
  13. public const VIRUS_SCAN_STATUS__PENDING = 'pending';
  14. public const VIRUS_SCAN_STATUS__IN_PROGRESS = 'in-progress';
  15. public const VIRUS_SCAN_STATUS__OK = 'no-threat';
  16. public const VIRUS_SCAN_STATUS__MALICIOUS = 'malicious';
  17. /**
  18. * @ORM\Column(name="id", type="integer")
  19. *
  20. * @ORM\Id
  21. *
  22. * @ORM\GeneratedValue(strategy="IDENTITY")
  23. */
  24. private ?int $id = null;
  25. /**
  26. * @ORM\Column(name="status", type="string", nullable=true)
  27. */
  28. private ?string $status = self::VIRUS_SCAN_STATUS__PENDING;
  29. /**
  30. * @ORM\Column(name="scanDate", type="datetime", nullable=true)
  31. */
  32. private ?\DateTimeImmutable $scanDate;
  33. /**
  34. * @ORM\OneToOne(targetEntity=Document::class, inversedBy="virusScanItem")
  35. */
  36. private ?Document $document = null;
  37. /**
  38. * @ORM\OneToOne(targetEntity=Disc::class, inversedBy="virusScanItem")
  39. */
  40. private ?Disc $disc = null;
  41. /**
  42. * @ORM\Column(name="path", type="string", nullable=true)
  43. */
  44. private ?string $path = null;
  45. /**
  46. * @return int|null
  47. */
  48. public function getId(): ?int
  49. {
  50. return $this->id;
  51. }
  52. /**
  53. * @return string|null
  54. */
  55. public function getStatus(): ?string
  56. {
  57. return $this->status;
  58. }
  59. /**
  60. * @param string $status
  61. *
  62. * @return self
  63. */
  64. public function setStatus(string $status): self
  65. {
  66. $this->status = $status;
  67. return $this;
  68. }
  69. /**
  70. * @return \DateTimeInterface|null
  71. */
  72. public function getScanDate(): ?\DateTimeInterface
  73. {
  74. return $this->scanDate;
  75. }
  76. /**
  77. * @param \DateTimeInterface $scanDate
  78. *
  79. * @return self
  80. */
  81. public function setScanDate(\DateTimeInterface $scanDate): self
  82. {
  83. $this->scanDate = $scanDate;
  84. return $this;
  85. }
  86. /**
  87. * @return Document|null
  88. */
  89. public function getDocument(): ?Document
  90. {
  91. return $this->document;
  92. }
  93. /**
  94. * @param Document|null $document
  95. *
  96. * @return self
  97. */
  98. public function setDocument(?Document $document): self
  99. {
  100. $this->document = $document;
  101. return $this;
  102. }
  103. /**
  104. * @return Disc|null
  105. */
  106. public function getDisc(): ?Disc
  107. {
  108. return $this->disc;
  109. }
  110. /**
  111. * @param Disc|null $disc
  112. *
  113. * @return self
  114. */
  115. public function setDisc(?Disc $disc): self
  116. {
  117. $this->disc = $disc;
  118. return $this;
  119. }
  120. /**
  121. * @param VirusScannableInterface $virusScannable
  122. *
  123. * @return self
  124. */
  125. public function setVirusScannable(VirusScannableInterface $virusScannable): self
  126. {
  127. $virusScannable->setVirusScanItem($this);
  128. return $this;
  129. }
  130. /**
  131. * @return VirusScannableInterface|null
  132. */
  133. public function getVirusScannable(): ?VirusScannableInterface
  134. {
  135. if ($this->getDocument() !== null) {
  136. return $this->getDocument();
  137. }
  138. return $this->getDisc();
  139. }
  140. /**
  141. * @return string|null
  142. */
  143. public function getPath(): ?string
  144. {
  145. return $this->path;
  146. }
  147. /**
  148. * @param string|null $path
  149. *
  150. * @return self
  151. */
  152. public function setPath(?string $path): self
  153. {
  154. $this->path = $path;
  155. return $this;
  156. }
  157. /**
  158. * @return bool
  159. */
  160. public function isMalicious(): bool
  161. {
  162. return $this->getStatus() === self::VIRUS_SCAN_STATUS__MALICIOUS;
  163. }
  164. /**
  165. * @return bool
  166. */
  167. public function isPending(): bool
  168. {
  169. return $this->getStatus() === self::VIRUS_SCAN_STATUS__PENDING;
  170. }
  171. }