| Total Complexity | 7 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 24 | final class Add implements Command |
||
| 25 | { |
||
| 26 | use JsonHelper; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @psalm-var array{commitWithin: ?int, doc: ?array, overwrite: ?bool} |
||
| 30 | */ |
||
| 31 | private array $options = [ |
||
| 32 | 'doc' => null, |
||
| 33 | 'commitWithin' => null, |
||
| 34 | 'overwrite' => null, |
||
| 35 | ]; |
||
| 36 | |||
| 37 | public function __construct(array $document) |
||
| 38 | { |
||
| 39 | $this->options['doc'] = $document; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @psalm-pure |
||
| 44 | */ |
||
| 45 | public static function create(array $document): self |
||
| 46 | { |
||
| 47 | return new self($document); |
||
| 48 | } |
||
| 49 | |||
| 50 | public function commitWithin(int $commitWithin): self |
||
| 51 | { |
||
| 52 | $add = clone $this; |
||
| 53 | $add->options['commitWithin'] = $commitWithin; |
||
| 54 | |||
| 55 | return $add; |
||
| 56 | } |
||
| 57 | |||
| 58 | public function enableOverWrite(): self |
||
| 59 | { |
||
| 60 | $add = clone $this; |
||
| 61 | $add->options['overwrite'] = true; |
||
| 62 | |||
| 63 | return $add; |
||
| 64 | } |
||
| 65 | |||
| 66 | public function disableOverWrite(): self |
||
| 67 | { |
||
| 68 | $add = clone $this; |
||
| 69 | $add->options['overwrite'] = false; |
||
| 70 | |||
| 71 | return $add; |
||
| 72 | } |
||
| 73 | |||
| 74 | public function toJson(): string |
||
| 75 | { |
||
| 76 | return self::jsonEncode(array_filter($this->options, static function ($option): bool { return null !== $option; })); |
||
| 77 | } |
||
| 78 | |||
| 79 | public function getName(): string |
||
| 82 | } |
||
| 83 | } |
||
| 84 |