Issues (2551)

src/Repository/DiagramElement.php (1 issue)

1
<?php
2
3
namespace Jabe\Repository;
4
5
abstract class DiagramElement implements \Serializable
6
{
7
    protected $id = null;
8
9
    public function __construct(?string $id = null)
10
    {
11
        $this->id = $id;
12
    }
13
14
    /**
15
     * Id of the diagram element.
16
     */
17
    public function getId(): string
18
    {
19
        return $this->id;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->id could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
20
    }
21
22
    public function setId(string $id): void
23
    {
24
        $this->id = $id;
25
    }
26
27
    public function __toString()
28
    {
29
        return "id=" . $this->getId();
30
    }
31
32
    public function serialize()
33
    {
34
        return json_encode([
35
            'id' => $this->id
36
        ]);
37
    }
38
39
    public function unserialize($data)
40
    {
41
        $json = json_decode($data);
42
        $this->id = $json->id;
43
    }
44
45
    abstract public function isNode(): bool;
46
    abstract public function isEdge(): bool;
47
}
48