Completed
Push — 1.x ( 8c7a9a...c7de71 )
by Markus
02:46
created

ParameterBag   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 65.22%

Importance

Changes 11
Bugs 3 Features 4
Metric Value
wmc 9
c 11
b 3
f 4
lcom 1
cbo 1
dl 0
loc 67
ccs 15
cts 23
cp 0.6522
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setParam() 0 6 1
A hasParams() 0 4 1
B toString() 0 22 5
A __toString() 0 4 1
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;
13
14
use Eluceo\iCal\Util\PropertyParameterValueUtil;
15
16
class ParameterBag
17
{
18
    /**
19
     * @var array
20
     */
21
    protected $params;
22
23 11
    public function __construct(array $params = [])
24
    {
25 11
        $this->params = $params;
26 11
    }
27
28
    /**
29
     * @param string $name
30
     * @param mixed  $value
31
     */
32 1
    public function setParam($name, $value)
33
    {
34 1
        assert(is_string($name), '$name parameter should be a string');
35
36 1
        $this->params[$name] = $value;
37 1
    }
38
39
    /**
40
     * Checks if there are any params.
41
     *
42
     * @return bool
43
     */
44
    public function hasParams()
45
    {
46
        return count($this->params) > 0;
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function toString()
53
    {
54
        $line = '';
55
56
        foreach ($this->params as $param => $paramValues) {
57
            if (!is_array($paramValues)) {
58
                $paramValues = [$paramValues];
59
            }
60
61
            foreach ($paramValues as $k => $v) {
62
                $paramValues[$k] = PropertyParameterValueUtil::escapeParamValue($v);
63
            }
64
65
            if ('' != $line) {
66
                $line .= ';';
67 8
            }
68
69 8
            $line .= $param . '=' . implode(',', $paramValues);
70
        }
71
72
        return $line;
73
    }
74
75 4
    /**
76
     * @return string
77 4
     */
78
    public function __toString()
79 4
    {
80 4
        return $this->toString();
81 4
    }
82
}
83