CurlOptions   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 29.4%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 94
ccs 5
cts 17
cp 0.294
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A offsetExists() 0 3 1
A all() 0 3 1
A replace() 0 3 1
A offsetUnset() 0 3 1
A offsetGet() 0 3 1
A offsetSet() 0 3 1
1
<?php
2
/**
3
 * php-guard/curl <https://github.com/php-guard/curl>
4
 * Copyright (C) ${YEAR} by Alexandre Le Borgne <[email protected]>.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
namespace PhpGuard\Curl\Collection;
21
22
class CurlOptions implements \ArrayAccess
23
{
24
    /**
25
     * @var array
26
     */
27
    private $options;
28
29 45
    public function __construct(array $options = [])
30
    {
31 45
        $this->options = $options;
32 45
    }
33
34
    /**
35
     * Whether a offset exists.
36
     *
37
     * @see https://php.net/manual/en/arrayaccess.offsetexists.php
38
     *
39
     * @param mixed $offset <p>
40
     *                      An offset to check for.
41
     *                      </p>
42
     *
43
     * @return bool true on success or false on failure.
44
     *              </p>
45
     *              <p>
46
     *              The return value will be casted to boolean if non-boolean was returned
47
     *
48
     * @since 5.0.0
49
     */
50
    public function offsetExists($offset)
51
    {
52
        return isset($this->options[$offset]);
53
    }
54
55
    /**
56
     * Offset to retrieve.
57
     *
58
     * @see https://php.net/manual/en/arrayaccess.offsetget.php
59
     *
60
     * @param mixed $offset <p>
61
     *                      The offset to retrieve.
62
     *                      </p>
63
     *
64
     * @return mixed can return all value types
65
     *
66
     * @since 5.0.0
67
     */
68
    public function offsetGet($offset)
69
    {
70
        return $this->options[$offset] ?? null;
71
    }
72
73
    /**
74
     * Offset to set.
75
     *
76
     * @see https://php.net/manual/en/arrayaccess.offsetset.php
77
     *
78
     * @param mixed $offset <p>
79
     *                      The offset to assign the value to.
80
     *                      </p>
81
     * @param mixed $value  <p>
82
     *                      The value to set.
83
     *                      </p>
84
     *
85
     * @since 5.0.0
86
     */
87
    public function offsetSet($offset, $value)
88
    {
89
        $this->options[$offset] = $value;
90
    }
91
92
    /**
93
     * Offset to unset.
94
     *
95
     * @see https://php.net/manual/en/arrayaccess.offsetunset.php
96
     *
97
     * @param mixed $offset <p>
98
     *                      The offset to unset.
99
     *                      </p>
100
     *
101
     * @since 5.0.0
102
     */
103
    public function offsetUnset($offset)
104
    {
105
        unset($this->options[$offset]);
106
    }
107
108
    public function replace(CurlOptions $options)
109
    {
110
        return new self(array_replace($this->options, $options->all()));
111
    }
112
113 45
    public function all()
114
    {
115 45
        return $this->options;
116
    }
117
}
118