Blameable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 37
dl 0
loc 64
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpdatedBy() 0 5 1
A getCreatedBy() 0 3 1
A getUpdatedBy() 0 3 1
A setCreatedBy() 0 5 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Entity/Traits/Blameable.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Entity\Traits;
10
11
use App\Entity\User;
12
use Doctrine\ORM\Mapping as ORM;
13
use Gedmo\Mapping\Annotation as Gedmo;
14
use Symfony\Component\Serializer\Annotation\Groups;
15
16
/**
17
 * Trait Blameable
18
 *
19
 * @package App\Entity\Traits
20
 * @author TLe, Tarmo Leppänen <[email protected]>
21
 */
22
trait Blameable
23
{
24
    #[ORM\ManyToOne(
25
        targetEntity: User::class,
26
    )]
27
    #[ORM\JoinColumn(
28
        name: 'created_by_id',
29
        referencedColumnName: 'id',
30
        nullable: true,
31
        onDelete: 'SET NULL',
32
    )]
33
    #[Gedmo\Blameable(
34
        on: 'create',
35
    )]
36
    #[Groups([
37
        'ApiKey.createdBy',
38
        'Role.createdBy',
39
        'User.createdBy',
40
        'UserGroup.createdBy',
41
    ])]
42
    protected ?User $createdBy = null;
43
44
    #[ORM\ManyToOne(
45
        targetEntity: User::class,
46
    )]
47
    #[ORM\JoinColumn(
48
        name: 'updated_by_id',
49
        referencedColumnName: 'id',
50
        nullable: true,
51
        onDelete: 'SET NULL',
52
    )]
53
    #[Gedmo\Blameable(
54
        on: 'update',
55
    )]
56
    #[Groups([
57
        'ApiKey.updatedBy',
58
        'Role.updatedBy',
59
        'User.updatedBy',
60
        'UserGroup.updatedBy',
61
    ])]
62
    protected ?User $updatedBy = null;
63
64 4
    public function getCreatedBy(): ?User
65
    {
66 4
        return $this->createdBy;
67
    }
68
69 8
    public function setCreatedBy(?User $createdBy = null): self
70
    {
71 8
        $this->createdBy = $createdBy;
72
73 8
        return $this;
74
    }
75
76 4
    public function getUpdatedBy(): ?User
77
    {
78 4
        return $this->updatedBy;
79
    }
80
81 8
    public function setUpdatedBy(?User $updatedBy = null): self
82
    {
83 8
        $this->updatedBy = $updatedBy;
84
85 8
        return $this;
86
    }
87
}
88