Skip to content

Commit 2b30d73

Browse files
committed
add ArrayBuilder
1 parent b694b9b commit 2b30d73

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/ArrayBuilder.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Utilitte\Php;
4+
5+
final class ArrayBuilder
6+
{
7+
8+
private array $values = [];
9+
10+
public static function create(): self
11+
{
12+
return new self();
13+
}
14+
15+
public function setValues(array $values): self
16+
{
17+
$this->values = $values;
18+
19+
return $this;
20+
}
21+
22+
public function addSkipIfEmpty(string $key, $values): self
23+
{
24+
if (!empty($values)) {
25+
$this->values[$key] = $values;
26+
}
27+
28+
return $this;
29+
}
30+
31+
public function addSkipIf(string $key, $values, bool $skip): self
32+
{
33+
if (!$skip) {
34+
$this->values[$key] = $values;
35+
}
36+
37+
return $this;
38+
}
39+
40+
public function appendSkipIf($values, bool $skip): self
41+
{
42+
if (!$skip) {
43+
$this->values[] = $values;
44+
}
45+
46+
return $this;
47+
}
48+
49+
public function append($values): self
50+
{
51+
$this->values[] = $values;
52+
53+
return $this;
54+
}
55+
56+
public function add(string $key, $values): self
57+
{
58+
$this->values[$key] = $values;
59+
60+
return $this;
61+
}
62+
63+
public function getResult(): array
64+
{
65+
return $this->values;
66+
}
67+
68+
}

0 commit comments

Comments
 (0)