Completed
Pull Request — 0.11.x (#104)
by
unknown
02:46
created

ComponentUtil   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 51.85%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 0
cbo 0
dl 0
loc 48
ccs 14
cts 27
cp 0.5185
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B fold() 0 34 6
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 $string
24
     *
25
     * @return array
26
     */
27 4
    public static function fold($string)
28
    {
29 4
        $lines = array();
30
31 4
        if (function_exists('mb_strcut')) {
32 4
            while (strlen($string) > 0) {
33 4
                if (strlen($string) > 75) {
34 1
                    $lines[] = mb_strcut($string, 0, 75, 'utf-8');
35 1
                    $string = ' ' . mb_strcut($string, 75, strlen($string), 'utf-8');
36 1
                } else {
37 4
                    $lines[] = $string;
38 4
                    $string = '';
0 ignored issues
show
Unused Code introduced by
$string is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
39 4
                    break;
40
                }
41 1
            }
42 4
        } else {
43
            $array = preg_split('/(?<!^)(?!$)/u', $string);
44
            $line = '';
45
            $lineNo = 0;
46
            foreach ($array as $char) {
47
                $charLen = strlen($char);
48
                $lineLen = strlen($line);
49
                if ($lineLen + $charLen > 75) {
50
                    $line = ' ' . $char;
51
                    ++$lineNo;
52
                } else {
53
                    $line .= $char;
54
                }
55
                $lines[$lineNo] = $line;
56
            }
57
        }
58
59 4
        return $lines;
60
    }
61
}
62