-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCollectionTuple.php
More file actions
57 lines (45 loc) · 1.4 KB
/
CollectionTuple.php
File metadata and controls
57 lines (45 loc) · 1.4 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
<?php
declare(strict_types=1);
namespace PHPSu\ShellCommandBuilder\Collection;
use PHPSu\ShellCommandBuilder\ShellInterface;
/**
* @internal
* @psalm-internal PHPSu\ShellCommandBuilder
*/
final class CollectionTuple implements ShellInterface
{
private string $join = '';
private ShellInterface|string $value = '';
private bool $noSpaceBeforeJoin = false;
private bool $noSpaceAfterJoin = false;
public static function create(ShellInterface|string $value, string $join = ''): self
{
$tuple = new self();
$tuple->value = $value;
$tuple->join = $join;
return $tuple;
}
public function noSpaceBeforeJoin(bool $space): self
{
$this->noSpaceBeforeJoin = $space;
return $this;
}
public function noSpaceAfterJoin(bool $space): self
{
$this->noSpaceAfterJoin = $space;
return $this;
}
/**
* @return array<ShellInterface|string|array<mixed>>
*/
public function __toArray(): array
{
$value = $this->value instanceof ShellInterface ? $this->value->__toArray() : $this->value;
return [$this->join, $value];
}
public function __toString(): string
{
/** @psalm-suppress ImplicitToStringCast **/
return sprintf('%s%s%s%s', $this->noSpaceBeforeJoin ? '' : ' ', $this->join, ($this->value === '' || $this->noSpaceAfterJoin) ? '' : ' ', $this->value);
}
}