ObservanceDecoratorFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A decorate() 0 10 5
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\HolidayIteratorItemInterface;
15
use Org_Heigl\Holidaychecker\ObservanceDecorator;
16
17
class ObservanceDecoratorFactory implements DecorateFromDomElement
18
{
19
	public function decorate(HolidayIteratorItemInterface $element, DOMElement $domElement): HolidayIteratorItemInterface
20
	{
21
		if (!$domElement->hasAttribute('firstobservance') && !$domElement->hasAttribute('lastobservance')) {
22
			return $element;
23
		}
24
25
		return new ObservanceDecorator(
26
			$element,
27
			$domElement->hasAttribute('firstobservance') ? (int) $domElement->getAttribute('firstobservance') : null,
28
			$domElement->hasAttribute('lastobservance') ? (int) $domElement->getAttribute('lastobservance') : null,
29
		);
30
	}
31
}
32