Delete   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 13
c 1
b 0
f 1
dl 0
loc 47
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getName() 0 3 1
A toJson() 0 7 2
A fromIds() 0 6 1
A fromQuery() 0 6 1
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