@@ -22,54 +22,54 @@ |
||
22 | 22 | |
23 | 23 | final class SwapDecoratorFactory implements DecorateFromDomElement |
24 | 24 | { |
25 | - public function decorate(HolidayIteratorItemInterface $element, DOMElement $domElement): HolidayIteratorItemInterface |
|
26 | - { |
|
27 | - $rules = $this->getRulesFromDomElement($domElement); |
|
25 | + public function decorate(HolidayIteratorItemInterface $element, DOMElement $domElement): HolidayIteratorItemInterface |
|
26 | + { |
|
27 | + $rules = $this->getRulesFromDomElement($domElement); |
|
28 | 28 | |
29 | - if ($rules === []) { |
|
30 | - return $element; |
|
31 | - } |
|
29 | + if ($rules === []) { |
|
30 | + return $element; |
|
31 | + } |
|
32 | 32 | |
33 | - $day = CalendarDayFactory::createCalendarDay( |
|
34 | - (int) $domElement->getAttribute('day'), |
|
35 | - (int) $domElement->getAttribute('month'), |
|
36 | - ($domElement->hasAttribute('calendar') ? $domElement->getAttribute('calendar') : 'gregorian') |
|
37 | - ); |
|
33 | + $day = CalendarDayFactory::createCalendarDay( |
|
34 | + (int) $domElement->getAttribute('day'), |
|
35 | + (int) $domElement->getAttribute('month'), |
|
36 | + ($domElement->hasAttribute('calendar') ? $domElement->getAttribute('calendar') : 'gregorian') |
|
37 | + ); |
|
38 | 38 | |
39 | - if ($domElement->hasAttribute('year')) { |
|
40 | - $day->setYear((int) $domElement->getAttribute('year')); |
|
41 | - } |
|
39 | + if ($domElement->hasAttribute('year')) { |
|
40 | + $day->setYear((int) $domElement->getAttribute('year')); |
|
41 | + } |
|
42 | 42 | |
43 | - return new SwapDecorator($element, $day, ...$rules); |
|
44 | - } |
|
43 | + return new SwapDecorator($element, $day, ...$rules); |
|
44 | + } |
|
45 | 45 | |
46 | - private function createRuleFrom(string $to, string $when, SwapDirection $direction): SwapRule |
|
47 | - { |
|
48 | - return new SwapRule( |
|
49 | - $direction, |
|
50 | - GregorianWeekday::fromString($to), |
|
51 | - ...array_map(function ($item) { |
|
52 | - return GregorianWeekday::fromString($item); |
|
53 | - }, explode(' ', $when)) |
|
54 | - ); |
|
55 | - } |
|
46 | + private function createRuleFrom(string $to, string $when, SwapDirection $direction): SwapRule |
|
47 | + { |
|
48 | + return new SwapRule( |
|
49 | + $direction, |
|
50 | + GregorianWeekday::fromString($to), |
|
51 | + ...array_map(function ($item) { |
|
52 | + return GregorianWeekday::fromString($item); |
|
53 | + }, explode(' ', $when)) |
|
54 | + ); |
|
55 | + } |
|
56 | 56 | |
57 | - private function getRulesFromDomElement(DOMElement $domElement): array |
|
58 | - { |
|
59 | - $attributes = [ |
|
60 | - 'forward' => SwapDirection::forward(), |
|
61 | - 'alternateforward' => SwapDirection::forward(), |
|
62 | - 'rewind' => SwapDirection::rewind(), |
|
63 | - 'alternaterewind' => SwapDirection::rewind(), |
|
64 | - ]; |
|
57 | + private function getRulesFromDomElement(DOMElement $domElement): array |
|
58 | + { |
|
59 | + $attributes = [ |
|
60 | + 'forward' => SwapDirection::forward(), |
|
61 | + 'alternateforward' => SwapDirection::forward(), |
|
62 | + 'rewind' => SwapDirection::rewind(), |
|
63 | + 'alternaterewind' => SwapDirection::rewind(), |
|
64 | + ]; |
|
65 | 65 | |
66 | - $rules = []; |
|
67 | - foreach ($attributes as $attribute => $direction) { |
|
68 | - if ($domElement->hasAttribute($attribute . 'to') && $domElement->hasAttribute($attribute . 'when')) { |
|
69 | - $rules[] = $this->createRuleFrom($domElement->getAttribute($attribute . 'to'), $domElement->getAttribute($attribute . 'when'), $direction); |
|
70 | - } |
|
71 | - } |
|
66 | + $rules = []; |
|
67 | + foreach ($attributes as $attribute => $direction) { |
|
68 | + if ($domElement->hasAttribute($attribute . 'to') && $domElement->hasAttribute($attribute . 'when')) { |
|
69 | + $rules[] = $this->createRuleFrom($domElement->getAttribute($attribute . 'to'), $domElement->getAttribute($attribute . 'when'), $direction); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - return $rules; |
|
74 | - } |
|
73 | + return $rules; |
|
74 | + } |
|
75 | 75 | } |