Electricity   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 63
ccs 28
cts 28
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 3
A loadFromArray() 0 10 2
A getType() 0 4 1
A getId() 0 4 1
A toJson() 0 4 1
1
<?php
2
3
namespace Dalen\OWLPacketInterceptor\Packet\Electricity;
4
5
use Dalen\OWLPacketInterceptor\Packet\Base;
6
use Dalen\OWLPacketInterceptor\Packet\IPacket;
7
use Dalen\OWLPacketInterceptor\Packet\Collection;
8
9
class Electricity extends Base implements IPacket
10
{
11
    
12 7
    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...
13
    {
14 7
        $this->fields = array
15
        (
16 7
            'id'        => '',
17 7
            'signal'    => NULL,
18 7
            'battery'   => NULL,
19 7
            'channels'  => new Collection(),
20
        );
21
        
22 7
        if(!empty($data))
23 7
        {
24 6
            parent::__construct(array('id' => $data['id']));
25
            
26 6
            if(is_array($data))
27 6
            {
28 6
                $this->loadFromArray($data);
29 6
            }
30 6
        }
31 7
    }
32
    
33
    /*
34
     * @parameter $data Array
35
     */
36 6
    private function loadFromArray($data)
37
    {
38 6
        foreach($data['chan'] AS $channel)
39
        {
40 6
            $this->fields['channels']->addItem(new Channel($channel));
41 6
        }
42
43 6
        $this->fields['signal']     =  new Signal($data['signal']);
44 6
        $this->fields['battery']    =  new Battery($data['battery']);
45 6
    }
46
    
47
    /*
48
     * returns the Domain's type
49
     */
50 1
    function getType()
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...
51
    {
52 1
        return get_class();
53
    }
54
55
    /*
56
     * returns the object id
57
     */
58 1
    public function getId()
59
    {
60 1
        return $this->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Dalen\OWLPacketIn...lectricity\Electricity>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61
    }
62
63
    /*
64
     * returns the Json representation of the object
65
     */
66 1
    public function toJson()
67
    {
68 1
        return json_encode($this);
69
    }
70
71
}