Completed
Push — master ( 762845...7b6129 )
by Joachim
01:40
created

KeyValueBuilder::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace Loevgaard\Dandomain\Api\KeyValueBuilder;
3
4
/**
5
 * The job of the key value builder is to make a fluent interface for creating a data structure like this:
6
 *
7
 * [
8
 *   'keyValues' => [
9
 *     ['Key' => 'property', 'Value' => 'new value of property']
10
 *   ]
11
 * ]
12
 *
13
 * to put into the patch methods
14
 */
15
class KeyValueBuilder
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
16
{
17
    /**
18
     * @var array
19
     */
20
    private $arr;
21
22 1
    private function __construct()
23
    {
24 1
        $this->arr = ['keyValues' => []];
25 1
    }
26
27 1
    public static function create() : KeyValueBuilder
28
    {
29 1
        return new self();
30
    }
31
32 1
    public function addPair(string $key, string $value) : KeyValueBuilder
33
    {
34 1
        $this->arr['keyValues'][] = [
35 1
            'Key' => $key, 'Value' => $value
36
        ];
37
38 1
        return $this;
39
    }
40
41 1
    public function build() : array
42
    {
43 1
        return $this->arr;
44
    }
45
}