src/Entity/Vulnerability.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\VulnerabilityRepository;
  4. use App\Traits\DateTimeTrait;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Overblog\GraphQLBundle\Annotation\Field;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\Common\Collections\ReadableCollection;
  10. use App\Attribute\Searchable;
  11. use DateTimeImmutable;
  12. #[ORM\Entity(repositoryClassVulnerabilityRepository::class)]
  13. #[ORM\HasLifecycleCallbacks]
  14. class Vulnerability extends BasicEntity
  15. {
  16.     use DateTimeTrait;
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column(type'integer')]
  20.     #[Field(name"id"type"int")]
  21.     private $id;
  22.     #[ORM\Column(type'string'length255)]
  23.     #[Field(name"title"type"string")]
  24.     #[Searchable(name'title')]
  25.     private $title;
  26.     #[ORM\Column(type'string'length255nullabletrue)]
  27.     #[Field(name"componenent"type"string")]
  28.     private $componenent;
  29.     #[ORM\Column(type'text'nullabletrue)]
  30.     #[Field(name"metadata"type"string")]
  31.     #[Searchable(name'metadata')]
  32.     private $metadata;
  33.     #[ORM\Column(type'text'nullabletrue)]
  34.     #[Field(name"description"type"string")]
  35.     private $description;
  36.     #[ORM\ManyToOne(targetEntityVulnerabilityLevel::class)]
  37.     #[ORM\JoinColumn(nullablefalse)]
  38.     #[Field(name"level"type"string")]
  39.     private $level;
  40.     #[ORM\ManyToOne(targetEntityDomain::class, inversedBy'vulnerabilities')]
  41.     #[ORM\JoinColumn(nullablefalse)]
  42.     #[Field(name"domain")]
  43.     private $domain;
  44.     #[ORM\Column(type'string'length255)]
  45.     #[Field(name"uid"type"string")]
  46.     private $uid;
  47.     #[ORM\OneToMany(mappedBy"vulnurability"targetEntityRecommendation::class, cascade: ["remove"])]
  48.     private $recommendations;
  49.     #[ORM\Column(type"boolean"options: ['default' => true])]
  50.     #[Field(name"is_active"type"boolean")]
  51.     private $isActive;
  52.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  53.     #[Field(name"last_seen"type"string")]
  54.     private $lastSeen;
  55.     #[ORM\ManyToOne(targetEntityStatus::class, inversedBy'exposedIps')]
  56.     #[ORM\JoinColumn(nullabletrueoptions: ['default' => 1])]
  57.     #[Field(name"status")]
  58.     private $status;
  59.     public function __construct()
  60.     {
  61.         $this->recommendations = new ArrayCollection();
  62.     }
  63.     public function getId(): ?int
  64.     {
  65.         return $this->id;
  66.     }
  67.     public function getTitle(): ?string
  68.     {
  69.         return $this->title;
  70.     }
  71.     public function setTitle(string $title): self
  72.     {
  73.         $this->title $title;
  74.         return $this;
  75.     }
  76.     public function getComponenent(): ?string
  77.     {
  78.         return $this->componenent;
  79.     }
  80.     public function setComponenent(?string $componenent): self
  81.     {
  82.         $this->componenent $componenent;
  83.         return $this;
  84.     }
  85.     public function getMetadata(): ?string
  86.     {
  87.         return $this->metadata;
  88.     }
  89.     public function setMetadata(?string $metadata): self
  90.     {
  91.         $this->metadata $metadata;
  92.         return $this;
  93.     }
  94.     public function getDescription(): ?string
  95.     {
  96.         return $this->description;
  97.     }
  98.     public function setDescription(?string $description): self
  99.     {
  100.         $this->description $description;
  101.         return $this;
  102.     }
  103.     public function getLevel(): ?VulnerabilityLevel
  104.     {
  105.         return $this->level;
  106.     }
  107.     public function setLevel(?VulnerabilityLevel $level): self
  108.     {
  109.         $this->level $level;
  110.         return $this;
  111.     }
  112.     public function getDomain(): ?Domain
  113.     {
  114.         return $this->domain;
  115.     }
  116.     public function setDomain(?Domain $domain): self
  117.     {
  118.         $this->domain $domain;
  119.         return $this;
  120.     }
  121.     public function getUid(): ?string
  122.     {
  123.         return $this->uid;
  124.     }
  125.     public function setUid(string $uid): self
  126.     {
  127.         $this->uid $uid;
  128.         return $this;
  129.     }
  130.     /**
  131.      * @return Collection|Recommendations[]
  132.      */
  133.     public function getRecommendations(): Collection
  134.     {
  135.         return $this->recommendations;
  136.     }
  137.     public function getIsActive(): ?bool
  138.     {
  139.         return $this->isActive;
  140.     }
  141.     public function setIsActive(?bool $isActive): self
  142.     {
  143.         $this->isActive $isActive;
  144.         return $this;
  145.     }
  146.     public function getLastSeen(): ?DateTimeImmutable
  147.     {
  148.         return $this->lastSeen;
  149.     }
  150.     public function setLastSeen(?DateTimeImmutable $lastSeen): self
  151.     {
  152.         $this->lastSeen $lastSeen;
  153.         return $this;
  154.     }
  155.     public function getStatus(): ?Status
  156.     {
  157.         return $this->status;
  158.     }
  159.     public function setStatus(?Status $status): self
  160.     {
  161.         $this->status $status;
  162.         return $this;
  163.     }
  164.     public function getSubDomain(): ?ExposedSubDomain
  165.     {
  166.         $metadata $this->getMetadata();
  167.         $subDomain $this->getDomain()->getExposedSubDomains()
  168.             ->filter(function(ExposedSubDomain $sub) use ($metadata){
  169.                return str_contains(
  170.                    $metadata,
  171.                    $sub->getSubDomain().".".str_replace('@'''$this->getDomain()->getUrl())
  172.                );
  173.             })->current();
  174.         
  175.         // Check if current() returned false and return null if so
  176.         return $subDomain !== false $subDomain null;
  177.     }
  178. }