Completed
Push — main ( d12b31...3b4b71 )
by Andreas
24s queued 12s
created

DateFactory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 16
c 1
b 0
f 0
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B itemFromDomElement() 0 24 8
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
use function explode;
18
19
class DateFactory implements ItemFromDomElementCreator
20
{
21
	public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface
22
	{
23
		if ($element->nodeName !== 'date') {
24
			return null;
25
		}
26
27
		$day = CalendarDayFactory::createCalendarDay(
28
			(int) $element->getAttribute('day'),
29
			(int) $element->getAttribute('month'),
30
			($element->hasAttribute('calendar') ? $element->getAttribute('calendar') : 'gregorian')
31
		);
32
33
		if ($element->hasAttribute('year')) {
34
			$day->setYear((int) $element->getAttribute('year'));
35
		}
36
37
		return new Date(
38
			$element->textContent,
39
            $element->getAttribute('free') === "true",
40
			$day,
41
			$element->hasAttribute('forwardto') ? $element->getAttribute('forwardto') : '',
42
			$element->hasAttribute('forwardwhen') ? explode(' ', $element->getAttribute('forwardwhen')) : [],
43
			$element->hasAttribute('rewindto') ? $element->getAttribute('rewindto') : '',
44
			$element->hasAttribute('rewindwhen') ? explode(' ', $element->getAttribute('rewindwhen')) : [],
45
		);
46
	}
47
}
48