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

DateFollowupFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A itemFromDomElement() 0 18 4
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
		return new DateFollowUp(
34
			$element->textContent,
35
			$element->getAttribute('free') === "true",
36
			$day,
37
			$element->getAttribute('followup'),
38
			($element->hasAttribute('replaced') ? explode(' ', $element->getAttribute('replaced')) : [])
39
		);
40
	}
41
}
42