SecurityEvent   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 15
eloc 34
c 1
b 0
f 0
dl 0
loc 103
rs 10

15 Methods

Rating   Name   Duplication   Size   Complexity  
A getUser() 0 3 1
A getEventTypeObject() 0 3 1
A __toString() 0 3 1
A getEventData() 0 3 1
A getIpAddress() 0 3 1
A setUser() 0 3 1
A getUserAgent() 0 3 1
A setEventData() 0 3 1
A getId() 0 3 1
A setIpAddress() 0 3 1
A setCreatedAt() 0 3 1
A getCreatedAt() 0 3 1
A getEventType() 0 3 1
A setEventType() 0 3 1
A setUserAgent() 0 3 1
1
<?php
2
3
namespace ProjetNormandie\UserBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use ProjetNormandie\UserBundle\Security\Event\SecurityEventTypeEnum;
7
8
#[ORM\Table(name: 'pnu_security_event')]
9
#[ORM\Entity]
10
#[ORM\Index(columns: ["user_id", "event_type", "created_at"], name: "search_idx")]
11
class SecurityEvent
12
{
13
    #[ORM\Id, ORM\Column, ORM\GeneratedValue]
14
    private ?int $id = null;
15
16
    #[ORM\ManyToOne(targetEntity: User::class)]
17
    #[ORM\JoinColumn(name: "user_id", referencedColumnName: "id", onDelete: "CASCADE")]
18
    private User $user;
19
20
    #[ORM\Column(type: 'string', length: 50)]
21
    private string $eventType;
22
23
    #[ORM\Column(type: 'datetime')]
24
    private \DateTime $createdAt;
25
26
    #[ORM\Column(type: 'json', nullable: true)]
27
    private ?array $eventData = null;
28
29
    #[ORM\Column(type: 'string', length: 45, nullable: true)]
30
    private ?string $ipAddress = null;
31
32
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
33
    private ?string $userAgent = null;
34
35
    public function getId(): ?int
36
    {
37
        return $this->id;
38
    }
39
40
    public function getUser(): User
41
    {
42
        return $this->user;
43
    }
44
45
    public function setUser(User $user): void
46
    {
47
        $this->user = $user;
48
    }
49
50
    public function getEventType(): string
51
    {
52
        return $this->eventType;
53
    }
54
55
    /**
56
     * Get the event type as a SecurityEventType object
57
     */
58
    public function getEventTypeObject(): SecurityEventTypeEnum
59
    {
60
        return SecurityEventTypeEnum::from($this->eventType);
61
    }
62
63
    public function setEventType(string $eventType): void
64
    {
65
        $this->eventType = $eventType;
66
    }
67
68
    public function getCreatedAt(): \DateTime
69
    {
70
        return $this->createdAt;
71
    }
72
73
    public function setCreatedAt(\DateTime $createdAt): void
74
    {
75
        $this->createdAt = $createdAt;
76
    }
77
78
    public function getEventData(): ?array
79
    {
80
        return $this->eventData;
81
    }
82
83
    public function setEventData(?array $eventData): void
84
    {
85
        $this->eventData = $eventData;
86
    }
87
88
    public function getIpAddress(): ?string
89
    {
90
        return $this->ipAddress;
91
    }
92
93
    public function setIpAddress(?string $ipAddress): void
94
    {
95
        $this->ipAddress = $ipAddress;
96
    }
97
98
    public function getUserAgent(): ?string
99
    {
100
        return $this->userAgent;
101
    }
102
103
    public function setUserAgent(?string $userAgent): void
104
    {
105
        $this->userAgent = $userAgent;
106
    }
107
108
    public function __toString()
109
    {
110
        return sprintf('%s#%s', $this->getUser()->getUserIdentifier(), $this->eventType);
111
    }
112
}
113