Test Setup Failed
Push — master ( ac8464...9588f8 )
by Andrey
03:17
created

CurrencyRateDate::createFromXML()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
/**
3
 * (c) itmedia.by <[email protected]>
4
 */
5
6
namespace Submarine\NbrbExchangeRatesBundle;
7
8
9
class CurrencyRateDate
10
{
11
    /**
12
     * @var \DateTime
13
     */
14
    private $date;
15
16
    /**
17
     * @var float
18
     */
19
    private $rate;
20
21
    /**
22
     * CurrencyRateDate constructor.
23
     * @param \DateTime $date
24
     * @param float $rate
25
     */
26
    public function __construct(\DateTime $date, $rate)
27
    {
28
        $this->date = $date;
29
        $this->rate = $rate;
30
    }
31
32
33
    static public function createFromXML(\SimpleXMLElement $xmlElement = null)
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
34
    {
35
        $dateArray = explode('/', (string)$xmlElement->attributes()[0]);
0 ignored issues
show
Bug introduced by
It seems like $xmlElement is not always an object, but can also be of type null. Maybe add an additional type check?

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();
    }
}
Loading history...
36
        if (count($dateArray) === 3) {
37
            $dateTime = new \DateTime();
38
            $dateTime->setDate($dateArray[2], $dateArray[0], $dateArray[1]);
39
            $dateTime->setTime(0, 0, 0);
40
41
            return new CurrencyRateDate($dateTime, (float)$xmlElement->Rate);
42
        }
43
44
        return new CurrencyRateDate(new \DateTime(), null);
45
    }
46
47
48
    /**
49
     * @return float
50
     */
51
    public function getRate()
52
    {
53
        return $this->rate;
54
    }
55
56
    /**
57
     * @return \DateTime
58
     */
59
    public function getDate()
60
    {
61
        return $this->date;
62
    }
63
64
65
}