for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Dalen\OWLPacketInterceptor\Parser\SpecificParser;
use Dalen\OWLPacketInterceptor\Parser\IParser;
use Dalen\OWLPacketInterceptor\Packet\Solar\Solar;
/**
* Description of SolarXMLParser
*
* @author danieleorler
*/
class SolarXMLParser implements IParser
{
/*
* sets the XMLElement containing packet's data
* @parameter \SimpleXMLElement $xmlElement
public function setXMLElement(\SimpleXMLElement $xmlElement)
$this->xmlElement = $xmlElement;
xmlElement
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;
}
* returns the Solar implementation of IPacket
public function parse()
$data = array();
$data['id'] = (string)$this->xmlElement->attributes()['id'];
$data['current']['generating']['units'] = (string)$this->xmlElement->current->generating->attributes()['units'];
$data['current']['generating']['value'] = (float)$this->xmlElement->current->generating;
$data['current']['exporting']['units'] = (string)$this->xmlElement->current->exporting->attributes()['units'];
$data['current']['exporting']['value'] = (float)$this->xmlElement->current->exporting;
$data['day']['generating']['units'] = (string)$this->xmlElement->day->generated->attributes()['units'];
$data['day']['generating']['value'] = (float)$this->xmlElement->day->generated;
$data['day']['exporting']['units'] = (string)$this->xmlElement->day->exported->attributes()['units'];
$data['day']['exporting']['value'] = (float)$this->xmlElement->day->exported;
return new Solar($data);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: