SolarXMLParser::parse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

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