ICalendarDateViewHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 4 1
A render() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\ViewHelpers\Format;
13
14
use DateTime;
15
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
16
17
/**
18
 * ICalendar Description viewHelper
19
 */
20
class ICalendarDateViewHelper extends AbstractViewHelper
21
{
22
    public function initializeArguments(): void
23
    {
24
        parent::initializeArguments();
25
        $this->registerArgument('date', 'datetime', 'The DateTime object', false);
26
    }
27
28
    /**
29
     * Formats the given date according to rfc5545
30
     *
31
     * @see http://tools.ietf.org/html/rfc5545#section-3.3.5
32
     */
33
    public function render(): string
34
    {
35
        $date = $this->arguments['date'] ?? null;
36
        if ($date === null) {
37
            $date = $this->renderChildren();
38
        }
39
        if ($date instanceof DateTime) {
40
            return gmdate('Ymd\THis\Z', $date->getTimestamp());
41
        }
42
43
        return '';
44
    }
45
}
46