Completed
Push — master ( ee3f46...2dd99c )
by Markus
03:13
created

ComponentUtil   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 0
cbo 0
dl 0
loc 35
ccs 16
cts 16
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fold() 0 21 3
1
<?php
2
3
/*
4
 * This file is part of the eluceo/iCal package.
5
 *
6
 * (c) Markus Poerschke <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Eluceo\iCal\Util;
13
14
class ComponentUtil
15
{
16
    /**
17
     * Folds a single line.
18
     *
19
     * According to RFC 2445, all lines longer than 75 characters will be folded
20
     *
21
     * @link http://www.ietf.org/rfc/rfc2445.txt
22
     *
23
     * @param $string
24
     *
25
     * @return array
26
     */
27 4
    public static function fold($string)
28
    {
29 4
        $lines = array();
30 4
        $array = preg_split('/(?<!^)(?!$)/u', $string);
31
32 4
        $line   = '';
33 4
        $lineNo = 0;
34 4
        foreach ($array as $char) {
35 4
            $charLen = strlen($char);
36 4
            $lineLen = strlen($line);
37 4
            if ($lineLen + $charLen > 75) {
38 1
                $line = ' ' . $char;
39 1
                ++$lineNo;
40 1
            } else {
41 4
                $line .= $char;
42
            }
43 4
            $lines[$lineNo] = $line;
44 4
        }
45
46 4
        return $lines;
47
    }
48
}
49