Completed
Push — main ( ec0f68...b41cf0 )
by Andreas
14s queued 12s
created

DateFactory::itemFromDomElement()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 23
rs 9.8333
cc 4
nc 3
nop 1
1
<?php
2
3
/**
4
 * Copyright Andreas Heigl <[email protected]>
5
 *
6
 * Licenses under the MIT-license. For details see the included file LICENSE.md
7
 */
8
9
declare(strict_types=1);
10
11
namespace Org_Heigl\Holidaychecker\Factory;
12
13
use DOMElement;
14
use Org_Heigl\Holidaychecker\CalendarDayFactory;
15
use Org_Heigl\Holidaychecker\HolidayIteratorItemInterface;
16
use Org_Heigl\Holidaychecker\IteratorItem\Date;
17
18
class DateFactory implements ItemFromDomElementCreator
19
{
20
	public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface
21
	{
22
		if ($element->nodeName !== 'date') {
23
			return null;
24
		}
25
26
		$day = CalendarDayFactory::createCalendarDay(
27
			(int) $element->getAttribute('day'),
28
			(int) $element->getAttribute('month'),
29
			($element->hasAttribute('calendar') ? $element->getAttribute('calendar') : 'gregorian')
30
		);
31
32
		if ($element->hasAttribute('year')) {
33
			$day->setYear((int) $element->getAttribute('year'));
34
		}
35
36
		$date = new Date(
37
			$element->textContent,
38
            $element->getAttribute('free') === "true",
39
			$day,
40
		);
41
42
		return $date;
43
	}
44
}
45