Commit::enableExpungeDeletes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Solr Client Symfony package.
7
 *
8
 * (c) ingatlan.com Zrt. <[email protected]>
9
 *
10
 * This source file is subject to the MIT license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13
14
namespace iCom\SolrClient\Query\Command;
15
16
use iCom\SolrClient\JsonHelper;
17
use iCom\SolrClient\Query\Command;
18
19
/**
20
 * @see https://lucene.apache.org/solr/guide/8_3/uploading-data-with-index-handlers.html#commit-and-optimize-during-updates
21
 *
22
 * @psalm-immutable
23
 */
24
final class Commit implements Command
25
{
26
    use JsonHelper;
27
28
    /**
29
     * @psalm-var array{waitSearcher: ?bool, expungeDeletes: ?bool}
30
     */
31
    private array $options = [
32
        'waitSearcher' => null,
33
        'expungeDeletes' => null,
34
    ];
35
36
    /**
37
     * @psalm-pure
38
     */
39
    public static function create(): self
40
    {
41
        return new self();
42
    }
43
44
    public function enableWaitSearcher(): self
45
    {
46
        $commit = clone $this;
47
        $commit->options['waitSearcher'] = true;
48
49
        return $commit;
50
    }
51
52
    public function disableWaitSearcher(): self
53
    {
54
        $commit = clone $this;
55
        $commit->options['waitSearcher'] = false;
56
57
        return $commit;
58
    }
59
60
    public function enableExpungeDeletes(): self
61
    {
62
        $commit = clone $this;
63
        $commit->options['expungeDeletes'] = true;
64
65
        return $commit;
66
    }
67
68
    public function disableExpungeDeletes(): self
69
    {
70
        $commit = clone $this;
71
        $commit->options['expungeDeletes'] = false;
72
73
        return $commit;
74
    }
75
76
    public function toJson(): string
77
    {
78
        return self::jsonEncode(array_filter($this->options, static function ($option): bool { return null !== $option; }), JSON_FORCE_OBJECT);
79
    }
80
81
    public function getName(): string
82
    {
83
        return 'commit';
84
    }
85
}
86