Completed
Push — master ( 203e38...2cdd54 )
by Gerrit
13:04
created

ValueObjectExample::createFromJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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);
0 ignored issues
show
Bug introduced by
The variable $scalarValue does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $lorem does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $dolor does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
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