SolarXMLParser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 34
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setXMLElement() 0 4 1
A parse() 0 17 1
1
<?php
2
3
namespace Dalen\OWLPacketInterceptor\Parser\SpecificParser;
4
5
use Dalen\OWLPacketInterceptor\Parser\IParser;
6
use Dalen\OWLPacketInterceptor\Packet\Solar\Solar;
7
8
/**
9
 * Description of SolarXMLParser
10
 *
11
 * @author danieleorler
12
 */
13
class SolarXMLParser implements IParser
14
{
15
16
    /*
17
     * sets the XMLElement containing packet's data
18
     * @parameter \SimpleXMLElement $xmlElement
19
     */
20 3
    public function setXMLElement(\SimpleXMLElement $xmlElement)
21
    {
22 3
        $this->xmlElement = $xmlElement;
0 ignored issues
show
Bug introduced by
The property xmlElement does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23 3
    }
24
    
25
    /*
26
     * returns the Solar implementation of IPacket
27
     */
28 2
    public function parse()
29
    {
30 2
        $data            = array();
31 2
        $data['id']      = (string)$this->xmlElement->attributes()['id'];
32
33 2
        $data['current']['generating']['units'] = (string)$this->xmlElement->current->generating->attributes()['units'];
34 2
        $data['current']['generating']['value'] = (float)$this->xmlElement->current->generating;
35 2
        $data['current']['exporting']['units']  = (string)$this->xmlElement->current->exporting->attributes()['units'];
36 2
        $data['current']['exporting']['value']  = (float)$this->xmlElement->current->exporting;
37
38 2
        $data['day']['generating']['units']     = (string)$this->xmlElement->day->generated->attributes()['units'];
39 2
        $data['day']['generating']['value']     = (float)$this->xmlElement->day->generated;
40 2
        $data['day']['exporting']['units']      = (string)$this->xmlElement->day->exported->attributes()['units'];
41 2
        $data['day']['exporting']['value']      = (float)$this->xmlElement->day->exported;
42
        
43 2
        return new Solar($data);
44
    }
45
46
}
47