FormRequestBuilder::build()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Buzz\Message;
6
7
class FormRequestBuilder
8
{
9
    /**
10
     * @var array
11
     */
12
    private $data;
13
14
    /**
15
     * @var array
16
     */
17
    private $files;
18
19 3
    public function __construct(array $data = [], array $files = [])
20
    {
21 3
        $this->data = $data;
22 3
        $this->files = $files;
23 3
    }
24
25 3
    public function addField(string $name, string $value): void
26
    {
27 3
        $this->data[$name] = $value;
28 3
    }
29
30 3
    public function addFile(string $name, string $path, string $contentType = null, string $filename = null): void
31
    {
32 3
        $this->files[$name] = [
33 3
            'path' => $path,
34 3
            'contentType' => $contentType,
35 3
            'filename' => $filename,
36
        ];
37 3
    }
38
39 3
    public function build(): array
40
    {
41 3
        $data = $this->data;
42
43 3
        foreach ($this->files as $name => $file) {
44 3
            $data[$name] = $file;
45
        }
46
47 3
        return $data;
48
    }
49
50
    /**
51
     * Reset the builder.
52
     */
53
    public function reset(): void
54
    {
55
        $this->data = [];
56
        $this->files = [];
57
    }
58
}
59