These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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
![]() |
|||
34 | { |
||
35 | $dateArray = explode('/', (string)$xmlElement->attributes()[0]); |
||
0 ignored issues
–
show
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();
}
}
![]() |
|||
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 | } |