Code Duplication    Length = 13-15 lines in 4 locations

src/Forms/DateField.php 2 locations

@@ 524-536 (lines=13) @@
521
     * @param string $date
522
     * @return string The formatted date, or null if not a valid date
523
     */
524
    protected function frontendToInternal($date)
525
    {
526
        if (!$date) {
527
            return null;
528
        }
529
        $fromFormatter = $this->getFrontendFormatter();
530
        $toFormatter = $this->getInternalFormatter();
531
        $timestamp = $fromFormatter->parse($date);
532
        if ($timestamp === false) {
533
            return null;
534
        }
535
        return $toFormatter->format($timestamp) ?: null;
536
    }
537
538
    /**
539
     * Convert the internal date representation (ISO 8601) to a format used by the frontend,
@@ 546-559 (lines=14) @@
543
     * @param string $date
544
     * @return string The formatted date, or null if not a valid date
545
     */
546
    protected function internalToFrontend($date)
547
    {
548
        $date = $this->tidyInternal($date);
549
        if (!$date) {
550
            return null;
551
        }
552
        $fromFormatter = $this->getInternalFormatter();
553
        $toFormatter = $this->getFrontendFormatter();
554
        $timestamp = $fromFormatter->parse($date);
555
        if ($timestamp === false) {
556
            return null;
557
        }
558
        return $toFormatter->format($timestamp) ?: null;
559
    }
560
561
    /**
562
     * Tidy up the internal date representation (ISO 8601),

src/Forms/DatetimeField.php 1 location

@@ 377-391 (lines=15) @@
374
     * @param string $datetime
375
     * @return string The formatted date and time, or null if not a valid date and time
376
     */
377
    public function internalToFrontend($datetime)
378
    {
379
        $datetime = $this->tidyInternal($datetime);
380
        if (!$datetime) {
381
            return null;
382
        }
383
        $fromFormatter = $this->getInternalFormatter();
384
        $toFormatter = $this->getFrontendFormatter();
385
        $timestamp = $fromFormatter->parse($datetime);
386
        if ($timestamp === false) {
387
            return null;
388
        }
389
390
        return $toFormatter->format($timestamp) ?: null;
391
    }
392
393
    /**
394
     * Tidy up the internal date representation (ISO 8601),

src/Forms/TimeField.php 1 location

@@ 416-429 (lines=14) @@
413
     * @param string $time
414
     * @return string
415
     */
416
    protected function internalToFrontend($time)
417
    {
418
        $time = $this->tidyInternal($time);
419
        if (!$time) {
420
            return null;
421
        }
422
        $fromFormatter = $this->getInternalFormatter();
423
        $toFormatter = $this->getFrontendFormatter();
424
        $timestamp = $fromFormatter->parse($time);
425
        if ($timestamp === false) {
426
            return null;
427
        }
428
        return $toFormatter->format($timestamp);
429
    }
430
431
432