MessageTrait::withAddedParameter()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 1
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Ivory Http Adapter package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\HttpAdapter\Message;
13
14
/**
15
 * @author GeLo <[email protected]>
16
 */
17
trait MessageTrait
18
{
19
    /**
20
     * @var array
21
     */
22
    private $parameters = [];
23
24
    /**
25
     * @return array
26
     */
27 14619
    public function getParameters()
28
    {
29 14619
        return $this->parameters;
30
    }
31
32
    /**
33
     * @param string $name
34
     *
35
     * @return bool
36
     */
37 393
    public function hasParameter($name)
38
    {
39 393
        return isset($this->parameters[$name]);
40
    }
41
42
    /**
43
     * @param string $name
44
     *
45
     * @return mixed
46
     */
47 393
    public function getParameter($name)
48
    {
49 393
        return $this->hasParameter($name) ? $this->parameters[$name] : null;
50
    }
51
52
    /**
53
     * @param string $name
54
     * @param mixed  $value
55
     *
56
     * @return object
57
     */
58 384
    public function withParameter($name, $value)
59
    {
60 384
        $new = clone $this;
61 384
        $new->parameters[$name] = $value;
62
63 384
        return $new;
64
    }
65
66
    /**
67
     * @param string $name
68
     * @param mixed  $value
69
     *
70
     * @return object
71
     */
72 9
    public function withAddedParameter($name, $value)
73
    {
74 9
        $new = clone $this;
75 9
        $new->parameters[$name] = $new->hasParameter($name)
76 9
            ? array_merge((array) $new->parameters[$name], (array) $value)
77 9
            : $value;
78
79 9
        return $new;
80
    }
81
82
    /**
83
     * @param string $name
84
     *
85
     * @return object
86
     */
87 9
    public function withoutParameter($name)
88
    {
89 9
        $new = clone $this;
90 9
        unset($new->parameters[$name]);
91
92 9
        return $new;
93
    }
94
}
95