ValueObjectExample::createFromJson()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
/**
3
 * Copyright (C) 2018 Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 *
8
 * @license GPL-3.0
9
 *
10
 * @author Gerrit Addiks <[email protected]>
11
 */
12
13
namespace Addiks\RDMBundle\Tests;
14
15
class ValueObjectExample
16
{
17
18
    /**
19
     * @var string
20
     */
21
    public $scalarValue = "lorem ipsum";
22
23
    /**
24
     * @var string
25
     */
26
    public $lorem = "ipsum";
27
28
    /**
29
     * @var int
30
     */
31
    public $dolor = 123;
32
33
    /**
34
     * @var mixed|null
35
     */
36
    public $sit;
37
38
    /**
39
     * @var mixed|null
40
     */
41
    private $amet;
42
43
    public function __construct(string $scalarValue, string $lorem = "ipsum", int $dolor = 123)
44
    {
45
        $this->scalarValue = $scalarValue;
46
        $this->lorem = $lorem;
47
        $this->dolor = $dolor;
48
    }
49
50
    public static function createFromJson(string $json)
51
    {
52
        [$scalarValue, $lorem, $dolor] = json_decode($json, true);
53
54
        return new self($scalarValue, $lorem, $dolor);
55
    }
56
57
    public function serializeJson()
58
    {
59
        return [$this->scalarValue, $this->lorem, $this->dolor];
60
    }
61
62
    public function setAmet($amet)
63
    {
64
        $this->amet = $amet;
65
    }
66
67
    public function getAmet()
68
    {
69
        return $this->amet;
70
    }
71
72
}
73