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

KeyValueBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 31
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 4 1
A addPair() 0 8 1
A build() 0 4 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
}