Completed
Pull Request — master (#16)
by Gordon
02:18
created

Indexer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setIndex() 0 3 1
A getIndexablePayload() 0 5 1
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\Base;
11
12
use SilverStripe\ORM\DataObject;
13
use Suilven\FreeTextSearch\Helper\IndexingHelper;
14
15
abstract class Indexer implements \Suilven\FreeTextSearch\Interfaces\Indexer
16
{
17
    /** @var string */
18
    protected $index;
19
20
    /**
21
     * Index a single data object
22
     */
23
    abstract public function index(DataObject $dataObject): void;
24
25
26
    /** @param string $newIndex the new index name */
27
    public function setIndex(string $newIndex): void
28
    {
29
        $this->index = $newIndex;
30
    }
31
32
    /**
33
     * @param \SilverStripe\ORM\DataObject $dataObject
34
     * @return array
35
     */
36
    protected function getIndexablePayload(\SilverStripe\ORM\DataObject $dataObject): array
37
    {
38
        $helper = new IndexingHelper();
39
        $payload = $helper->getFieldsToIndex($dataObject);
40
        return $payload;
41
    }
42
}
43