Passed
Push — addIntervalForBefrijdingsdag ( b5e81e...27ae7d )
by Andreas
01:35
created
src/HolidayIteratorItemInterface.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@
 block discarded – undo
36 36
 
37 37
 interface HolidayIteratorItemInterface
38 38
 {
39
-	public function dateMatches(DateTimeInterface $date): bool;
39
+    public function dateMatches(DateTimeInterface $date): bool;
40 40
 
41
-	public function getName(): string;
41
+    public function getName(): string;
42 42
 
43
-	public function isHoliday(): bool;
43
+    public function isHoliday(): bool;
44 44
 }
Please login to merge, or discard this patch.
src/HolidayIteratorFactory.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -52,109 +52,109 @@
 block discarded – undo
52 52
 
53 53
 class HolidayIteratorFactory
54 54
 {
55
-	/** @var ItemFromDomElementCreator[] */
56
-	private $factories;
57
-
58
-	/** @var DecorateFromDomElement[] */
59
-	private $decorators;
60
-
61
-	public function __construct()
62
-	{
63
-		$this->factories = [
64
-			new EasterFactory(),
65
-			new EasterOrthodoxFactory(),
66
-			new DateFactory(),
67
-			new DateFollowupFactory(),
68
-			new RelativeFactory(),
69
-		];
70
-
71
-		$this->decorators = [
72
-			new ObservanceDecoratorFactory(),
73
-			new SwapDecoratorFactory(),
74
-		];
75
-	}
76
-
77
-	/**
78
-	 * Create a HolidayIterator from an ISO 3166-code.
79
-	 *
80
-	 * @param string $isoCode
81
-	 *
82
-	 * @return HolidayIterator
83
-	 */
84
-	public function createIteratorFromISO3166(string $isoCode): HolidayIterator
85
-	{
86
-		$file = __DIR__ . '/../share/%s.xml';
87
-		$file1 = sprintf($file, $isoCode);
88
-
89
-		if (!is_readable($file1)) {
90
-			throw new UnexpectedValueException(sprintf(
91
-				'There is no holiday-file for %s',
92
-				$isoCode
93
-			));
94
-		}
95
-
96
-		return $this->createIteratorFromXmlFile($file1);
97
-	}
98
-
99
-	/**
100
-	 * Create a HolidayIterator from an XML-File
101
-	 *
102
-	 * The provided XML-File has to validate against the holiday.xsd-file you
103
-	 * can find in this projects "share" folder.
104
-	 *
105
-	 * @param string $file
106
-	 *
107
-	 * @return HolidayIterator
108
-	 */
109
-	public function createIteratorFromXmlFile(string $file): HolidayIterator
110
-	{
111
-		$iterator = new HolidayIterator();
112
-
113
-		$dom = new DOMDocument('1.0', 'UTF-8');
114
-		$dom->load($file);
115
-		$dom->xinclude();
116
-
117
-		if (!@$dom->schemaValidate(__DIR__ . '/../share/holidays.xsd')) {
118
-			throw new Exception('XML-File does not validate agains schema');
119
-		}
120
-		foreach ($dom->documentElement->childNodes as $child) {
121
-			if (!$child instanceof DOMElement) {
122
-				continue;
123
-			}
124
-			if ($child->nodeName === 'resources') {
125
-				continue;
126
-			}
127
-
128
-			try {
129
-				$element = $this->getElement($child);
130
-				$element = $this->decorateElement($element, $child);
131
-				$iterator->append($element);
132
-			} catch (Throwable $e) {
133
-				// Do nothing on purpose
134
-			}
135
-		}
136
-
137
-		return $iterator;
138
-	}
139
-
140
-	private function getElement(DOMElement $child): HolidayIteratorItemInterface
141
-	{
142
-		foreach ($this->factories as $factory) {
143
-			$element = $factory->itemFromDomElement($child);
144
-			if ($element instanceof HolidayIteratorItemInterface) {
145
-				return $element;
146
-			}
147
-		}
148
-
149
-		throw new RuntimeException('Unknown element encountered');
150
-	}
151
-
152
-	private function decorateElement(HolidayIteratorItemInterface $element, DOMElement $child): HolidayIteratorItemInterface
153
-	{
154
-		foreach ($this->decorators as $decorator) {
155
-			$element = $decorator->decorate($element, $child);
156
-		}
157
-
158
-		return $element;
159
-	}
55
+    /** @var ItemFromDomElementCreator[] */
56
+    private $factories;
57
+
58
+    /** @var DecorateFromDomElement[] */
59
+    private $decorators;
60
+
61
+    public function __construct()
62
+    {
63
+        $this->factories = [
64
+            new EasterFactory(),
65
+            new EasterOrthodoxFactory(),
66
+            new DateFactory(),
67
+            new DateFollowupFactory(),
68
+            new RelativeFactory(),
69
+        ];
70
+
71
+        $this->decorators = [
72
+            new ObservanceDecoratorFactory(),
73
+            new SwapDecoratorFactory(),
74
+        ];
75
+    }
76
+
77
+    /**
78
+     * Create a HolidayIterator from an ISO 3166-code.
79
+     *
80
+     * @param string $isoCode
81
+     *
82
+     * @return HolidayIterator
83
+     */
84
+    public function createIteratorFromISO3166(string $isoCode): HolidayIterator
85
+    {
86
+        $file = __DIR__ . '/../share/%s.xml';
87
+        $file1 = sprintf($file, $isoCode);
88
+
89
+        if (!is_readable($file1)) {
90
+            throw new UnexpectedValueException(sprintf(
91
+                'There is no holiday-file for %s',
92
+                $isoCode
93
+            ));
94
+        }
95
+
96
+        return $this->createIteratorFromXmlFile($file1);
97
+    }
98
+
99
+    /**
100
+     * Create a HolidayIterator from an XML-File
101
+     *
102
+     * The provided XML-File has to validate against the holiday.xsd-file you
103
+     * can find in this projects "share" folder.
104
+     *
105
+     * @param string $file
106
+     *
107
+     * @return HolidayIterator
108
+     */
109
+    public function createIteratorFromXmlFile(string $file): HolidayIterator
110
+    {
111
+        $iterator = new HolidayIterator();
112
+
113
+        $dom = new DOMDocument('1.0', 'UTF-8');
114
+        $dom->load($file);
115
+        $dom->xinclude();
116
+
117
+        if (!@$dom->schemaValidate(__DIR__ . '/../share/holidays.xsd')) {
118
+            throw new Exception('XML-File does not validate agains schema');
119
+        }
120
+        foreach ($dom->documentElement->childNodes as $child) {
121
+            if (!$child instanceof DOMElement) {
122
+                continue;
123
+            }
124
+            if ($child->nodeName === 'resources') {
125
+                continue;
126
+            }
127
+
128
+            try {
129
+                $element = $this->getElement($child);
130
+                $element = $this->decorateElement($element, $child);
131
+                $iterator->append($element);
132
+            } catch (Throwable $e) {
133
+                // Do nothing on purpose
134
+            }
135
+        }
136
+
137
+        return $iterator;
138
+    }
139
+
140
+    private function getElement(DOMElement $child): HolidayIteratorItemInterface
141
+    {
142
+        foreach ($this->factories as $factory) {
143
+            $element = $factory->itemFromDomElement($child);
144
+            if ($element instanceof HolidayIteratorItemInterface) {
145
+                return $element;
146
+            }
147
+        }
148
+
149
+        throw new RuntimeException('Unknown element encountered');
150
+    }
151
+
152
+    private function decorateElement(HolidayIteratorItemInterface $element, DOMElement $child): HolidayIteratorItemInterface
153
+    {
154
+        foreach ($this->decorators as $decorator) {
155
+            $element = $decorator->decorate($element, $child);
156
+        }
157
+
158
+        return $element;
159
+    }
160 160
 }
Please login to merge, or discard this patch.
src/Calendar.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -36,38 +36,38 @@
 block discarded – undo
36 36
 
37 37
 class Calendar
38 38
 {
39
-	public const BUDDHIST = 'buddhist';
40
-	public const CHINESE = 'chinese';
41
-	public const COPTIC = 'coptic';
42
-	public const ETHIOPIAN = 'ethiopian';
43
-	public const GREGORIAN = 'gregorian';
44
-	public const HEBREW = 'hebrew';
45
-	public const INDIAN = 'indian';
46
-	public const ISLAMIC = 'islamic';
47
-	public const ISLAMIC_CIVIL = 'islamic-civil';
48
-	public const ISLAMIC_UMALQURA = 'islamic-umalqura';
49
-	public const ISLAMIC_RGSA = 'islamic-rgsa';
50
-	public const ISLAMIC_TBLA = 'islamic-tbla';
51
-	public const JAPANESE = 'japanese';
52
-	public const PERSIAN = 'persian';
39
+    public const BUDDHIST = 'buddhist';
40
+    public const CHINESE = 'chinese';
41
+    public const COPTIC = 'coptic';
42
+    public const ETHIOPIAN = 'ethiopian';
43
+    public const GREGORIAN = 'gregorian';
44
+    public const HEBREW = 'hebrew';
45
+    public const INDIAN = 'indian';
46
+    public const ISLAMIC = 'islamic';
47
+    public const ISLAMIC_CIVIL = 'islamic-civil';
48
+    public const ISLAMIC_UMALQURA = 'islamic-umalqura';
49
+    public const ISLAMIC_RGSA = 'islamic-rgsa';
50
+    public const ISLAMIC_TBLA = 'islamic-tbla';
51
+    public const JAPANESE = 'japanese';
52
+    public const PERSIAN = 'persian';
53 53
 
54
-	public static function isValidCalendarName(string $calendarname): bool
55
-	{
56
-		return in_array($calendarname, [
57
-			self::BUDDHIST,
58
-			self::CHINESE,
59
-			self::COPTIC,
60
-			self::ETHIOPIAN,
61
-			self::GREGORIAN,
62
-			self::HEBREW,
63
-			self::INDIAN,
64
-			self::ISLAMIC,
65
-			self::ISLAMIC_CIVIL,
66
-			self::ISLAMIC_RGSA,
67
-			self::ISLAMIC_TBLA,
68
-			self::ISLAMIC_UMALQURA,
69
-			self::JAPANESE,
70
-			self::PERSIAN,
71
-		]);
72
-	}
54
+    public static function isValidCalendarName(string $calendarname): bool
55
+    {
56
+        return in_array($calendarname, [
57
+            self::BUDDHIST,
58
+            self::CHINESE,
59
+            self::COPTIC,
60
+            self::ETHIOPIAN,
61
+            self::GREGORIAN,
62
+            self::HEBREW,
63
+            self::INDIAN,
64
+            self::ISLAMIC,
65
+            self::ISLAMIC_CIVIL,
66
+            self::ISLAMIC_RGSA,
67
+            self::ISLAMIC_TBLA,
68
+            self::ISLAMIC_UMALQURA,
69
+            self::JAPANESE,
70
+            self::PERSIAN,
71
+        ]);
72
+    }
73 73
 }
Please login to merge, or discard this patch.
src/ObservanceDecorator.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -14,47 +14,47 @@
 block discarded – undo
14 14
 
15 15
 final class ObservanceDecorator implements HolidayIteratorItemInterface
16 16
 {
17
-	/** @var int|null */
18
-	private $firstObservance;
19
-
20
-	/** @var int|null */
21
-	private $lastObservance;
22
-
23
-	/** @var HolidayIteratorItemInterface */
24
-	private $wrapped;
25
-
26
-	public function __construct(HolidayIteratorItemInterface $wrapped, ?int $firstObservance, ?int $lastObservance)
27
-	{
28
-		$this->wrapped = $wrapped;
29
-		$this->firstObservance = $firstObservance;
30
-		$this->lastObservance = $lastObservance;
31
-	}
32
-
33
-	public function dateMatches(DateTimeInterface $date): bool
34
-	{
35
-		if (!$this->isWithinObservance((int) $date->format('Y'))) {
36
-			return false;
37
-		}
38
-
39
-		return $this->wrapped->dateMatches($date);
40
-	}
41
-
42
-	private function isWithinObservance(int $gregorianYear): bool
43
-	{
44
-		if (null !== $this->firstObservance && $this->firstObservance > $gregorianYear) {
45
-			return false;
46
-		}
47
-
48
-		return null === $this->lastObservance || $this->lastObservance >= $gregorianYear;
49
-	}
50
-
51
-	public function getName(): string
52
-	{
53
-		return $this->wrapped->getName();
54
-	}
55
-
56
-	public function isHoliday(): bool
57
-	{
58
-		return $this->wrapped->isHoliday();
59
-	}
17
+    /** @var int|null */
18
+    private $firstObservance;
19
+
20
+    /** @var int|null */
21
+    private $lastObservance;
22
+
23
+    /** @var HolidayIteratorItemInterface */
24
+    private $wrapped;
25
+
26
+    public function __construct(HolidayIteratorItemInterface $wrapped, ?int $firstObservance, ?int $lastObservance)
27
+    {
28
+        $this->wrapped = $wrapped;
29
+        $this->firstObservance = $firstObservance;
30
+        $this->lastObservance = $lastObservance;
31
+    }
32
+
33
+    public function dateMatches(DateTimeInterface $date): bool
34
+    {
35
+        if (!$this->isWithinObservance((int) $date->format('Y'))) {
36
+            return false;
37
+        }
38
+
39
+        return $this->wrapped->dateMatches($date);
40
+    }
41
+
42
+    private function isWithinObservance(int $gregorianYear): bool
43
+    {
44
+        if (null !== $this->firstObservance && $this->firstObservance > $gregorianYear) {
45
+            return false;
46
+        }
47
+
48
+        return null === $this->lastObservance || $this->lastObservance >= $gregorianYear;
49
+    }
50
+
51
+    public function getName(): string
52
+    {
53
+        return $this->wrapped->getName();
54
+    }
55
+
56
+    public function isHoliday(): bool
57
+    {
58
+        return $this->wrapped->isHoliday();
59
+    }
60 60
 }
Please login to merge, or discard this patch.
src/Holidaychecker.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -36,21 +36,21 @@
 block discarded – undo
36 36
 
37 37
 class Holidaychecker
38 38
 {
39
-	private $iterator;
40
-
41
-	public function __construct(HolidayIterator $iterator)
42
-	{
43
-		$this->iterator = $iterator;
44
-	}
45
-
46
-	public function check(DateTimeInterface $date): Holiday
47
-	{
48
-		foreach ($this->iterator as $entry) {
49
-			if ($entry->dateMatches($date)) {
50
-				return new Holiday($entry->isHoliday(), $entry->getName());
51
-			}
52
-		}
53
-
54
-		return new Holiday(false);
55
-	}
39
+    private $iterator;
40
+
41
+    public function __construct(HolidayIterator $iterator)
42
+    {
43
+        $this->iterator = $iterator;
44
+    }
45
+
46
+    public function check(DateTimeInterface $date): Holiday
47
+    {
48
+        foreach ($this->iterator as $entry) {
49
+            if ($entry->dateMatches($date)) {
50
+                return new Holiday($entry->isHoliday(), $entry->getName());
51
+            }
52
+        }
53
+
54
+        return new Holiday(false);
55
+    }
56 56
 }
Please login to merge, or discard this patch.
src/SwapDirection.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -12,50 +12,50 @@
 block discarded – undo
12 12
 
13 13
 final class SwapDirection
14 14
 {
15
-	private const FORWARD = 'forward';
16
-	private const REWIND = 'rewind';
17
-	/** @var array<string, self> */
18
-	private static $instances = [];
19
-	/** @var string */
20
-	private $value;
21
-
22
-	private function __construct(string $value)
23
-	{
24
-		$this->value = $value;
25
-	}
26
-
27
-	public static function forward(): self
28
-	{
29
-		if (!isset(self::$instances[self::FORWARD])) {
30
-			self::$instances[self::FORWARD] = new self(self::FORWARD);
31
-		}
32
-
33
-		return self::$instances[self::FORWARD];
34
-	}
35
-
36
-	public static function rewind(): self
37
-	{
38
-		if (!isset(self::$instances[self::REWIND])) {
39
-			self::$instances[self::REWIND] = new self(self::REWIND);
40
-		}
41
-
42
-		return self::$instances[self::REWIND];
43
-	}
44
-
45
-	public function getValue(): string
46
-	{
47
-		return $this->value;
48
-	}
49
-
50
-	public function getDateTimeDirection(): string
51
-	{
52
-		switch ($this->value) {
53
-			case self::REWIND:
54
-				return 'previous';
55
-			case self::FORWARD:
56
-				return 'next';
57
-		}
58
-
59
-		return '';
60
-	}
15
+    private const FORWARD = 'forward';
16
+    private const REWIND = 'rewind';
17
+    /** @var array<string, self> */
18
+    private static $instances = [];
19
+    /** @var string */
20
+    private $value;
21
+
22
+    private function __construct(string $value)
23
+    {
24
+        $this->value = $value;
25
+    }
26
+
27
+    public static function forward(): self
28
+    {
29
+        if (!isset(self::$instances[self::FORWARD])) {
30
+            self::$instances[self::FORWARD] = new self(self::FORWARD);
31
+        }
32
+
33
+        return self::$instances[self::FORWARD];
34
+    }
35
+
36
+    public static function rewind(): self
37
+    {
38
+        if (!isset(self::$instances[self::REWIND])) {
39
+            self::$instances[self::REWIND] = new self(self::REWIND);
40
+        }
41
+
42
+        return self::$instances[self::REWIND];
43
+    }
44
+
45
+    public function getValue(): string
46
+    {
47
+        return $this->value;
48
+    }
49
+
50
+    public function getDateTimeDirection(): string
51
+    {
52
+        switch ($this->value) {
53
+            case self::REWIND:
54
+                return 'previous';
55
+            case self::FORWARD:
56
+                return 'next';
57
+        }
58
+
59
+        return '';
60
+    }
61 61
 }
Please login to merge, or discard this patch.
src/CalendarDayFactory.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -38,22 +38,22 @@
 block discarded – undo
38 38
 
39 39
 class CalendarDayFactory
40 40
 {
41
-	public static function createCalendarDay(int $day, int $month, string $calendar): CalendarDay
42
-	{
43
-		if (!Calendar::isValidCalendarName($calendar)) {
44
-			throw new UnknownCalendar(sprintf(
45
-				'The calendar %s is not known to the ICU',
46
-				$calendar
47
-			));
48
-		}
49
-		$icuCalendar = IntlCalendar::createInstance('UTC', '@calendar=' . $calendar);
41
+    public static function createCalendarDay(int $day, int $month, string $calendar): CalendarDay
42
+    {
43
+        if (!Calendar::isValidCalendarName($calendar)) {
44
+            throw new UnknownCalendar(sprintf(
45
+                'The calendar %s is not known to the ICU',
46
+                $calendar
47
+            ));
48
+        }
49
+        $icuCalendar = IntlCalendar::createInstance('UTC', '@calendar=' . $calendar);
50 50
 
51
-		if ($icuCalendar === null) {
52
-			throw new UnknownCalendar(sprintf(
53
-				'The %s calendar could not be created',
54
-				$calendar
55
-			));
56
-		}
57
-		return new CalendarDay($day, $month, $icuCalendar);
58
-	}
51
+        if ($icuCalendar === null) {
52
+            throw new UnknownCalendar(sprintf(
53
+                'The %s calendar could not be created',
54
+                $calendar
55
+            ));
56
+        }
57
+        return new CalendarDay($day, $month, $icuCalendar);
58
+    }
59 59
 }
Please login to merge, or discard this patch.