Passed
Pull Request — master (#8)
by Gábor
11:04
created

Delete::__clone()   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
    private function __clone()
39
    {
40
    }
41
42
    /**
43
     * @psalm-pure
44
     */
45
    public static function fromIds(array $ids): self
46
    {
47
        $delete = new self();
48
        $delete->value = $ids;
49
50
        return $delete;
51
    }
52
53
    /**
54
     * @psalm-pure
55
     */
56
    public static function fromQuery(SelectQuery $query): self
57
    {
58
        $delete = new self();
59
        $delete->value = $query;
60
61
        return $delete;
62
    }
63
64
    public function toJson(): string
65
    {
66
        if ($this->value instanceof SelectQuery) {
67
            return $this->value->toJson();
68
        }
69
70
        return self::jsonEncode($this->value);
71
    }
72
73
    public function getName(): string
74
    {
75
        return 'delete';
76
    }
77
}
78