Passed
Pull Request — develop (#167)
by
unknown
20:25
created

TcaIndexer::getIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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 52
     */
43
    public function __construct(
44
        TcaTableServiceInterface $tcaTableService,
45
        ConnectionInterface $connection,
46
        ConfigurationContainerInterface $configuration
47 52
    ) {
48 52
        parent::__construct($connection, $configuration);
49 52
        $this->tcaTableService = $tcaTableService;
50
    }
51
52
    /**
53
     * @param integer $offset
54 24
     * @param integer $limit
55
     * @return array|null
56 24
     */
57 24
    protected function getRecords(int $offset, int $limit)
58 24
    {
59
        $records = $this->tcaTableService->getRecords($offset, $limit);
60
        if ($records === []) {
61 24
            return null;
62 24
        }
63 24
64
        $this->tcaTableService->filterRecordsByRootLineBlacklist($records);
65
        foreach ($records as &$record) {
66 24
            $this->tcaTableService->prepareRecord($record);
67
        }
68
69
        return $records;
70
    }
71
72 4
    /**
73
     * @param integer $identifier
74 4
     * @return array
75
     * @throws NoRecordFoundException If record could not be found.
76 4
     */
77 2
    protected function getRecord(int $identifier): array
78 2
    {
79 2
        $record = $this->tcaTableService->getRecord($identifier);
80
        if ($record === []) {
81
            throw new NoRecordFoundException(
82 2
                'Record could not be fetched from database: "' . $identifier . '". Perhaps record is not active.',
83
                1484225364
84 2
            );
85
        }
86
        $this->tcaTableService->prepareRecord($record);
87 28
88
        return $record;
89 28
    }
90
91
    /**
92
     * @return string
93
     */
94
    protected function getDocumentName(): string
95
    {
96
        return $this->tcaTableService->getTableName();
97
    }
98
99
    /**
100
     * @param string $identifier
101
     * @return string
102
     */
103
    public function getIdentifier($identifier): string
104
    {
105
        return $this->getDocumentName() . '-' . $identifier;
106
    }
107
}
108