Base   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 86.96%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 45
ccs 20
cts 23
cp 0.8696
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A __set() 0 7 2
A __get() 0 11 2
A __isset() 0 4 1
A jsonSerialize() 0 4 1
1
<?php
2
3
namespace Dalen\OWLPacketInterceptor\Packet;
4
5
/**
6
 * Description of Base
7
 *
8
 * @author danieleorler
9
 */
10
class Base implements \JsonSerializable
11
{
12
    protected $fields;
13
14 30
    function __construct($data = NULL)
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...
15
    {
16 30
        if($data !== NULL)
17 30
        {
18 30
            foreach($data AS $key=>$value)
19
            {
20 30
                $this->__set($key,$value);
21 30
            }
22 30
        }
23 30
    }
24
25 30
    public function __set($key, $value)
26
    {
27 30
        if(array_key_exists($key, $this->fields))
28 30
        {
29 30
            $this->fields[$key] = $value;
30 30
        }
31 30
    }
32
33 13
    public function __get($key)
34
    {
35 13
        if(array_key_exists($key, $this->fields))
36 13
        {
37 13
            return $this->fields[$key];
38
        }
39
        else
40
        {
41
            throw new \Exception("$key is not a valid property of class ".__CLASS__); 
42
        }
43
    }
44
    
45
    public function __isset($name)
46
    {
47
        return array_key_exists($name, $this->fields);
48
    }
49
50 11
    public function jsonSerialize()
51
    {
52 11
        return $this->fields;
53
    }
54
}
55