Completed
Push — master ( 4e56c1...a65fb9 )
by Tim
47s queued 10s
created

EscapeIcalTextViewHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 5 1
A render() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace HDNET\Calendarize\ViewHelpers\Format;
6
7
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
8
9
/**
10
 * EscapeIcalTextViewHelper.
11
 */
12
class EscapeIcalTextViewHelper extends AbstractViewHelper
13
{
14
    /**
15
     * @var bool
16
     */
17
    protected $escapeChildren = false;
18
19
    /**
20
     * Disable the output escaping interceptor so that the value is not htmlspecialchar'd twice.
21
     *
22
     * @var bool
23
     */
24
    protected $escapeOutput = false;
25
26
    public function initializeArguments()
27
    {
28
        parent::initializeArguments();
29
        $this->registerArgument('value', 'string', 'Value to format');
30
    }
31
32
    /**
33
     * Escapes special characters for ICalendar TEXT defined in RFC 5545 - 3.3.11.
34
     *
35
     * @return string the altered string
36
     *
37
     * @see https://tools.ietf.org/html/rfc5545#section-3.3.11
38
     *
39
     * @api
40
     */
41
    public function render()
42
    {
43
        $value = $this->arguments['value'];
44
        if (null === $value) {
45
            $value = $this->renderChildren();
46
        }
47
        // Note: The string syntax use double and single quotes!
48
        return str_replace(["\\", "\n", "\r", ",", ";"], ['\\\\', '\n', '\r', '\,', '\;'], $value);
49
    }
50
}
51