Base::__isset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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