ElectricityXMLParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setXMLElement() 0 4 1
B parse() 0 30 4
1
<?php
2
3
namespace Dalen\OWLPacketInterceptor\Parser\SpecificParser;
4
5
use Dalen\OWLPacketInterceptor\Parser\IParser;
6
use Dalen\OWLPacketInterceptor\Packet\Electricity\Electricity;
7
8
/**
9
 * Description of ElectricityXMLParser
10
 *
11
 * @author danieleorler
12
 */
13
class ElectricityXMLParser implements IParser
14
{
15
    private $xmlElement;
16
    
17
    /*
18
     * sets the XMLElement containing packet's data
19
     * @parameter \SimpleXMLElement $xmlElement
20
     */
21 3
    public function setXMLElement(\SimpleXMLElement $xmlElement)
22
    {
23 3
        $this->xmlElement = $xmlElement;
24 3
    }
25
    
26
    /*
27
     * returns the Electricity implementation of IPacket
28
     */
29 2
    public function parse()
30
    {
31 2
        $data            = array();
32 2
        $data['id']      = (string)$this->xmlElement->attributes()['id'];
33 2
        $data['chan']    = array();
34
35 2
        foreach($this->xmlElement->signal->attributes() AS $k => $v)
36
        {
37 2
            $data['signal'][$k] = (string)$v;
38 2
        }
39
        
40 2
        foreach($this->xmlElement->battery->attributes() AS $k => $v)
41
        {
42 2
            $data['battery'][$k] = (string)$v;
43 2
        }
44
        
45 2
        foreach($this->xmlElement->chan AS $chan)
46
        {
47 2
            $channel                    = array();
48 2
            $channel['id']              = (int)$chan->attributes()['id'];
49 2
            $channel['curr']['units']   = (string)$chan->curr->attributes()['units'];
50 2
            $channel['curr']['value']   = (float)$chan->curr;
51 2
            $channel['day']['units']    = (string)$chan->day->attributes()['units'];
52 2
            $channel['day']['value']    = (float)$chan->day;
53
            
54 2
            $data['chan'][]      = $channel;
55 2
        }
56
        
57 2
        return new Electricity($data);
58
    }
59
}
60