Passed
Push — master ( 3d6cc6...98cf1e )
by Gábor
02:53
created

Delete::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
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
use iCom\SolrClient\Query\SelectQuery;
19
20
/**
21
 * @see https://lucene.apache.org/solr/guide/8_3/uploading-data-with-index-handlers.html#delete-operations
22
 *
23
 * @psalm-immutable
24
 */
25
final class Delete implements Command
26
{
27
    use JsonHelper;
28
29
    /**
30
     * @var array|SelectQuery
31
     */
32
    private $value = [];
33
34
    private function __construct()
35
    {
36
    }
37
38
    /**
39
     * @psalm-pure
40
     */
41
    public static function fromIds(array $ids): self
42
    {
43
        $delete = new self();
44
        $delete->value = $ids;
45
46
        return $delete;
47
    }
48
49
    /**
50
     * @psalm-pure
51
     */
52
    public static function fromQuery(SelectQuery $query): self
53
    {
54
        $delete = new self();
55
        $delete->value = $query;
56
57
        return $delete;
58
    }
59
60
    public function toJson(): string
61
    {
62
        if ($this->value instanceof SelectQuery) {
63
            return $this->value->toJson();
64
        }
65
66
        return self::jsonEncode($this->value);
67
    }
68
69
    public function getName(): string
70
    {
71
        return 'delete';
72
    }
73
}
74