for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* (c) itmedia.by <[email protected]>
*/
namespace Submarine\NbrbExchangeRatesBundle;
class CurrencyRateDate
{
* @var \DateTime
private $date;
* @var float
private $rate;
* CurrencyRateDate constructor.
* @param \DateTime $date
* @param float $rate
public function __construct(\DateTime $date, $rate)
$this->date = $date;
$this->rate = $rate;
}
static public function createFromXML(\SimpleXMLElement $xmlElement = null)
static
$dateArray = explode('/', (string)$xmlElement->attributes()[0]);
$xmlElement
null
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:
function someFunction(A $objectMaybe = null) { if ($objectMaybe instanceof A) { $objectMaybe->doSomething(); } }
if (count($dateArray) === 3) {
$dateTime = new \DateTime();
$dateTime->setDate($dateArray[2], $dateArray[0], $dateArray[1]);
$dateTime->setTime(0, 0, 0);
return new CurrencyRateDate($dateTime, (float)$xmlElement->Rate);
return new CurrencyRateDate(new \DateTime(), null);
* @return float
public function getRate()
return $this->rate;
* @return \DateTime
public function getDate()
return $this->date;