FormRequestBuilder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 50
ccs 18
cts 21
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A reset() 0 4 1
A addFile() 0 6 1
A build() 0 9 2
A __construct() 0 4 1
A addField() 0 3 1
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