Code Duplication    Length = 30-31 lines in 2 locations

apps/dav/lib/CalDAV/CalDavBackend.php 1 location

@@ 2031-2060 (lines=30) @@
2028
		if ($componentType === 'VEVENT' && $component->DTSTART) {
2029
			$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
2030
			// Finding the last occurrence is a bit harder
2031
			if (!isset($component->RRULE)) {
2032
				if (isset($component->DTEND)) {
2033
					$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
2034
				} elseif (isset($component->DURATION)) {
2035
					$endDate = clone $component->DTSTART->getDateTime();
2036
					$endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
2037
					$lastOccurrence = $endDate->getTimeStamp();
2038
				} elseif (!$component->DTSTART->hasTime()) {
2039
					$endDate = clone $component->DTSTART->getDateTime();
2040
					$endDate->modify('+1 day');
2041
					$lastOccurrence = $endDate->getTimeStamp();
2042
				} else {
2043
					$lastOccurrence = $firstOccurrence;
2044
				}
2045
			} else {
2046
				$it = new EventIterator($vObject, (string)$component->UID);
2047
				$maxDate = new \DateTime(self::MAX_DATE);
2048
				if ($it->isInfinite()) {
2049
					$lastOccurrence = $maxDate->getTimestamp();
2050
				} else {
2051
					$end = $it->getDtEnd();
2052
					while($it->valid() && $end < $maxDate) {
2053
						$end = $it->getDtEnd();
2054
						$it->next();
2055
2056
					}
2057
					$lastOccurrence = $end->getTimestamp();
2058
				}
2059
2060
			}
2061
		}
2062
2063
		if ($component->CLASS) {

apps/dav/lib/CalDAV/Schedule/IMipPlugin.php 1 location

@@ 261-291 (lines=31) @@
258
259
		$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
260
		// Finding the last occurrence is a bit harder
261
		if (!isset($component->RRULE)) {
262
			if (isset($component->DTEND)) {
263
				$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
264
			} elseif (isset($component->DURATION)) {
265
				/** @var \DateTime $endDate */
266
				$endDate = clone $component->DTSTART->getDateTime();
267
				// $component->DTEND->getDateTime() returns DateTimeImmutable
268
				$endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
269
				$lastOccurrence = $endDate->getTimestamp();
270
			} elseif (!$component->DTSTART->hasTime()) {
271
				/** @var \DateTime $endDate */
272
				$endDate = clone $component->DTSTART->getDateTime();
273
				// $component->DTSTART->getDateTime() returns DateTimeImmutable
274
				$endDate = $endDate->modify('+1 day');
275
				$lastOccurrence = $endDate->getTimestamp();
276
			} else {
277
				$lastOccurrence = $firstOccurrence;
278
			}
279
		} else {
280
			$it = new EventIterator($vObject, (string)$component->UID);
281
			$maxDate = new \DateTime(self::MAX_DATE);
282
			if ($it->isInfinite()) {
283
				$lastOccurrence = $maxDate->getTimestamp();
284
			} else {
285
				$end = $it->getDtEnd();
286
				while($it->valid() && $end < $maxDate) {
287
					$end = $it->getDtEnd();
288
					$it->next();
289
290
				}
291
				$lastOccurrence = $end->getTimestamp();
292
			}
293
		}
294