Completed
Push — master ( 126c8c...32cbdd )
by Tim
15s queued 11s
created

LineFoldingViewHelper   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A renderStatic() 0 18 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace HDNET\Calendarize\ViewHelpers\Format;
6
7
use HDNET\Calendarize\ViewHelpers\AbstractViewHelper;
8
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
9
10
/**
11
 * Class LineFoldingViewHelper.
12
 *
13
 * Splits long lines (>75 characters) into multiple lines and prepends a space.
14
 */
15
class LineFoldingViewHelper extends AbstractViewHelper
16
{
17
    /**
18
     * @var bool
19
     */
20
    protected $escapeOutput = false;
21
22
    /**
23
     * @param array                     $arguments
24
     * @param \Closure                  $renderChildrenClosure
25
     * @param RenderingContextInterface $renderingContext
26
     *
27
     * @return string
28
     */
29
    public static function renderStatic(
30
        array $arguments,
31
        \Closure $renderChildrenClosure,
32
        RenderingContextInterface $renderingContext
33
    ): string {
34
        return preg_replace(
35
            // Line folding after 75 characters: RFC-5545/3-1-content-lines
36
            // Base on: sabre/vobject
37
             '/(
38
                 (?:^.)?         # 1 additional byte in first line because of missing single space (see next line)
39
                 .{74}           # 75 bytes per line (1 byte is used for a single space added after every CRLF)
40
                 (?![\x80-\xbf]) # prevent splitting multibyte characters
41
                 (?=[^\r\n])     # exclude last match in a line to prevent extra match or linebreak
42
             )/x',
43
            "$1\n ",
44
            $renderChildrenClosure()
45
        );
46
    }
47
}
48