Passed
Pull Request — master (#8)
by Gábor
03:36
created

Delete   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

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

6 Methods

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