SerializableContainerTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 44
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainer() 0 4 1
A serialize() 0 4 1
A unserialize() 0 4 1
A jsonSerialize() 0 4 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