DateFollowupFactory::itemFromDomElement()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 24
rs 9.7666
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\DateFollowUp;
17
use function explode;
18
19
class DateFollowupFactory implements ItemFromDomElementCreator
20
{
21
	public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface
22
	{
23
		if ($element->nodeName !== 'dateFollowUp') {
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
		$replaced = [];
34
		if ($element->hasAttribute('replaced')) {
35
			/** @var array<"sunday"|"monday"|"tuesday"|"wednesday"|"thursday"|"friday"|"saturday"> $replaced */
36
			$replaced = explode(' ', $element->getAttribute('replaced'));
37
		}
38
39
		return new DateFollowUp(
40
			$element->textContent,
41
			$element->getAttribute('free') === "true",
42
			$day,
43
			$element->getAttribute('followup'),
44
			$replaced
45
		);
46
	}
47
}
48