Completed
Push — master ( 6db1e1...6c89f6 )
by BENOIT
04:54
created

EditableULIDTrait::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BenTools;
4
5
use Doctrine\ORM\Mapping\Column;
6
use Doctrine\ORM\Mapping\GeneratedValue;
7
use Doctrine\ORM\Mapping\Id;
8
use Doctrine\ORM\Mapping\PrePersist;
9
use Ulid\Ulid;
10
11
trait EditableULIDTrait
12
{
13
    /**
14
     * @var string
15
     *
16
     * @Id()
17
     * @GeneratedValue(strategy="NONE")
18
     * @Column(type="string", length=26)
19
     */
20
    private $id;
21
22
    /**
23
     * @return string
24
     */
25
    public function getId(): ?string
26
    {
27
        return $this->id;
28
    }
29
30
    /**
31
     * @param string $id
32
     */
33
    public function setId(string $id): void
34
    {
35
        $this->id = $id;
36
    }
37
38
    /**
39
     * @PrePersist()
40
     * @internal
41
     */
42
    public function _setIdOnPersist()
43
    {
44
        if (null !== $this->id) {
45
            return;
46
        }
47
48
        $this->id = (string) Ulid::generate();
49
    }
50
}
51