DataObject   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 42
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromData() 0 8 1
A jsonSerialize() 0 4 1
A jsonUnserialize() 0 3 1
1
<?php
2
namespace Slack;
3
4
/**
5
 * A serializable model object that stores its data in a hash.
6
 */
7
abstract class DataObject implements \JsonSerializable
8
{
9
    /**
10
     * @var array The object's data cache.
11
     */
12
    public $data = [];
13
14
    /**
15
     * Creates a data object from an array of data.
16
     *
17
     * @param array $data The array containing object data.
18
     *
19
     * @return self A new object instance.
20
     */
21 18
    public static function fromData(array $data)
22
    {
23 18
        $reflection = new \ReflectionClass(static::class);
24 18
        $instance = $reflection->newInstanceWithoutConstructor();
25 18
        $instance->data = $data;
26 18
        $instance->jsonUnserialize($data);
27 18
        return $instance;
28
    }
29
30
    /**
31
     * Returns scalar data to be serialized.
32
     *
33
     * @return array
34
     */
35
    public function jsonSerialize()
36
    {
37
        return $this->data;
38
    }
39
40
    /**
41
     * Re-initializes the object when unserialized or created from a data array.
42
     *
43
     * @param array $data The object data.
44
     */
45 4
    public function jsonUnserialize(array $data)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    {
47 4
    }
48
}
49