DeserializeTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deserialize() 0 18 5
A deserializeExtra() 0 1 1
1
<?php
2
3
namespace BWC\Share\Object;
4
5
6
trait DeserializeTrait
7
{
8
9
    /**
10
     * @param $data
11
     * @return null|static
12
     */
13
    static function deserialize($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14
        $result = null;
15
        $arr = null;
16
        if (is_string($data)) {
17
            $arr = json_decode($data, true);
18
        } else if (is_array($data)) {
19
            $arr = $data;
20
        } else if(is_object($data)){
21
            $arr = get_object_vars($data);
22
        }
23
        if ($arr) {
24
            /** @var $result DeserializeTrait */
25
            $result = new static();
26
            ObjectHelper::copyExistingProperties($arr, $result);
27
            $result->deserializeExtra($arr);
28
        }
29
        return $result;
30
    }
31
32
    function deserializeExtra($arr) { }
0 ignored issues
show
Unused Code introduced by
The parameter $arr 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...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
33
34
}