Passed
Push — master ( 9cf181...0135fb )
by Gordon
05:12 queued 02:38
created

BulkIndexer::resetIndexedPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
/**
4
 * Created by PhpStorm.
5
 * User: gordon
6
 * Date: 24/3/2561
7
 * Time: 20:36 น.
8
 */
9
10
namespace Suilven\FreeTextSearch\Tests\Mock;
11
12
use SilverStripe\ORM\DataObject;
13
use Suilven\FreeTextSearch\Helper\IndexingHelper;
14
15
// @phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
16
class BulkIndexer implements \Suilven\FreeTextSearch\Interfaces\BulkIndexer
17
{
18
19
    /** @var string */
20
    private static $indexName;
21
22
    /** @var array<string, (string|int|float|bool)>|null */
23
    private static $payload = [];
24
25
26
    public function addDataObject(DataObject $dataObject): void
27
    {
28
        $helper = new IndexingHelper();
29
30
        $payload = $helper->getFieldsToIndex($dataObject);
31
32
        // as we are not indexing against a real free text search engine, add the ID into the payload for testing
33
        $payload['ID'] = $dataObject->ID;
34
        self::$payload[] = $payload;
35
    }
36
37
38
    public function indexDataObjects(): void
39
    {
40
        // noop - this is a mock, so no implementation required
41
    }
42
43
44
    public function setIndex(string $newIndex): void
45
    {
46
        self::$indexName = $newIndex;
47
    }
48
49
50
    public static function getIndexName(): string
51
    {
52
        return self::$indexName;
53
    }
54
55
56
    /** @return array<string, (string|int|float|bool)>|null */
57
    public static function getIndexedPayload(): ?array
58
    {
59
        return self::$payload;
60
    }
61
62
63
    public static function resetIndexedPayload(): void
64
    {
65
        self::$payload = [];
66
    }
67
}
68