-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncodeOptions.php
More file actions
95 lines (76 loc) · 2.09 KB
/
Copy pathEncodeOptions.php
File metadata and controls
95 lines (76 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace ToonLite;
/**
* Configuration options for TOON encoding.
*/
final class EncodeOptions
{
private int $indentSize;
private bool $trailingNewline;
private bool $minify;
public function __construct(
int $indentSize = 2,
bool $trailingNewline = true,
bool $minify = false
) {
if ($indentSize < 0) {
throw new \InvalidArgumentException('indentSize must be >= 0');
}
$this->indentSize = $indentSize;
$this->trailingNewline = $trailingNewline;
$this->minify = $minify;
}
public static function defaults(): self
{
return new self();
}
// ----- Getters -----
public function getIndentSize(): int
{
return $this->indentSize;
}
public function getTrailingNewline(): bool
{
return $this->trailingNewline;
}
public function isMinify(): bool
{
return $this->minify;
}
public function hasTrailingNewline(): bool
{
return $this->trailingNewline;
}
// ----- Mutable setters -----
public function setIndentSize(int $indentSize): self
{
if ($indentSize < 0) {
throw new \InvalidArgumentException('indentSize must be >= 0');
}
$this->indentSize = $indentSize;
return $this;
}
public function setTrailingNewline(bool $trailingNewline): self
{
$this->trailingNewline = $trailingNewline;
return $this;
}
public function setMinify(bool $minify): self
{
$this->minify = $minify;
return $this;
}
// ----- Immutable-style "with" helpers -----
public function withIndentSize(int $indentSize): self
{
return new self($indentSize, $this->trailingNewline, $this->minify);
}
public function withTrailingNewline(bool $trailingNewline): self
{
return new self($this->indentSize, $trailingNewline, $this->minify);
}
public function withMinify(bool $minify): self
{
return new self($this->indentSize, $this->trailingNewline, $minify);
}
}