Completed
Push — 1.x ( 8c7a9a...c7de71 )
by Markus
04:41 queued 02:47
created

PropertyParameterValueUtil::escapeParamValue()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 8.8571
cc 5
eloc 8
nc 2
nop 1
crap 5
1
<?php
2
3
namespace Eluceo\iCal\Util;
4
5
abstract class PropertyParameterValueUtil
6
{
7
    /**
8
     * Returns an escaped string for a param value.
9
     *
10
     * @param string $value
11
     *
12
     * @return string
13
     */
14 8
    public static function escapeParamValue($value)
15
    {
16 8
        $count = 0;
17 8
        $value = str_replace('\\', '\\\\', $value);
18 8
        $value = str_replace('"', '\"', $value, $count);
19 8
        $value = str_replace("\n", '\\n', $value);
20
21 8
        if (false !== strpos($value, ';') || false !== strpos($value, ',') || false !== strpos($value, ':') || $count) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $count of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
22 4
            $value = '"' . $value . '"';
23 4
        }
24
25 8
        return $value;
26
    }
27
}
28