KVs::withoutPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * Key and values
4
 * User: moyo
5
 * Date: 16/10/2017
6
 * Time: 11:49 AM
7
 */
8
9
namespace Carno\Consul\Types;
10
11
use Carno\Consul\Chips\SVersions;
12
use ArrayObject;
13
14
class KVs extends ArrayObject
15
{
16
    use SVersions;
17
18
    /**
19
     * KVs constructor.
20
     * @param string $path
21
     * @param array $data
22
     */
23
    public function __construct(string $path, array $data)
24
    {
25
        foreach ($data as $kv) {
26
            $this->offsetSet($this->withoutPath($path, $kv['Key']), base64_decode($kv['Value']));
27
        }
28
    }
29
30
    /**
31
     * @param string $path
32
     * @param string $key
33
     * @return string
34
     */
35
    private function withoutPath(string $path, string $key) : string
36
    {
37
        return substr($key, strlen($path) + 1);
38
    }
39
}
40