Completed
Push — master ( 9f147e...c59a3d )
by Kristof
05:32
created

OrganizerProjectedToJSONLD::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * @file
4
 */
5
6
namespace CultuurNet\UDB3\Organizer;
7
8
use Broadway\Serializer\SerializableInterface;
9
10
class OrganizerProjectedToJSONLD implements SerializableInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    private $id;
16
17
    /**
18
     * @param string $id
19
     * @param string $iri
20
     */
21
    public function __construct($id, $iri)
22
    {
23
        $this->id = (string) $id;
24
        $this->iri = (string) $iri;
0 ignored issues
show
Bug introduced by
The property iri does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function getId()
31
    {
32
        return $this->id;
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getIri()
39
    {
40
        return $this->iri;
41
    }
42
43
    /**
44
     * @return array
45
     */
46
    public function serialize()
47
    {
48
        return [
49
            'id' => $this->getId(),
50
            'iri' => $this->getIri(),
51
        ];
52
    }
53
54
    /**
55
     * @param array $data
56
     * @return OrganizerProjectedToJSONLD
57
     */
58
    public static function deserialize(array $data)
59
    {
60
        return new self($data['id'], $data['iri']);
61
    }
62
}
63