Passed
Pull Request — develop (#167)
by Daniel
05:07
created

TcaIndexer::getDocumentIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Codappix\SearchCore\Domain\Index;
4
5
/*
6
 * Copyright (C) 2016  Daniel Siepmann <[email protected]>
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
 * 02110-1301, USA.
22
 */
23
24
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
25
use Codappix\SearchCore\Connection\ConnectionInterface;
26
use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableServiceInterface;
27
28
/**
29
 * Will index the given table using configuration from TCA.
30
 */
31
class TcaIndexer extends AbstractIndexer
32
{
33
    /**
34
     * @var TcaTableServiceInterface
35
     */
36
    protected $tcaTableService;
37
38
    /**
39
     * @param TcaTableServiceInterface $tcaTableService
40
     * @param ConnectionInterface $connection
41
     * @param ConfigurationContainerInterface $configuration
42
     */
43 30
    public function __construct(
44
        TcaTableServiceInterface $tcaTableService,
45
        ConnectionInterface $connection,
46
        ConfigurationContainerInterface $configuration
47
    ) {
48 30
        parent::__construct($connection, $configuration);
49 30
        $this->tcaTableService = $tcaTableService;
50 30
    }
51
52 4
    protected function getRecords(int $offset, int $limit): array
53
    {
54 4
        $records = $this->tcaTableService->getRecords($offset, $limit);
55 2
        if ($records === []) {
56 2
            return [];
57
        }
58
59 2
        $this->tcaTableService->filterRecordsByRootLineBlacklist($records);
60 2
        foreach ($records as &$record) {
61 2
            $this->tcaTableService->prepareRecord($record);
62
        }
63
64 2
        return $records;
65
    }
66
67
    /**
68
     * @throws NoRecordFoundException If record could not be found.
69
     */
70
    protected function getRecord(int $identifier): array
71
    {
72
        $record = $this->tcaTableService->getRecord($identifier);
73
        if ($record === []) {
74
            throw new NoRecordFoundException(
75
                'Record could not be fetched from database: "' . $identifier . '". Perhaps record is not active.',
76
                1484225364
77
            );
78
        }
79
        $this->tcaTableService->prepareRecord($record);
80
81
        return $record;
82
    }
83
84 2
    protected function getDocumentName(): string
85
    {
86 2
        return $this->tcaTableService->getTableName();
87
    }
88
89 2
    public function getDocumentIdentifier($identifier): string
90
    {
91 2
        return $this->getDocumentName() . '-' . $identifier;
92
    }
93
}
94