SerializableContainerTrait::getContainer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Bouhnosaure\Dogecoin;
4
5
trait SerializableContainerTrait
6
{
7
    /**
8
     * Gets container.
9
     *
10
     * @return array
11
     */
12 9
    public function getContainer()
13
    {
14 9
        return $this->container;
0 ignored issues
show
Bug introduced by
The property container 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...
15
    }
16
17
    /**
18
     * Returns the string representation of the object.
19
     *
20
     * @return string
21
     */
22 6
    public function serialize()
23
    {
24 6
        return serialize($this->container);
25
    }
26
27
    /**
28
     * Constructs object from serialized string.
29
     *
30
     * @param string $serialized
31
     *
32
     * @return void
33
     */
34 3
    public function unserialize($serialized)
35
    {
36 3
        $this->container = unserialize($serialized);
37 3
    }
38
39
    /**
40
     * Serializes the object to a value that can be serialized by json_encode().
41
     *
42
     * @return array
43
     */
44 3
    public function jsonSerialize()
45
    {
46 3
        return $this->container;
47
    }
48
}
49