TASK: Cleanup type annotations and phpstan issues

This commit is contained in:
Daniel Siepmann 2018-03-06 17:40:49 +01:00
parent 88f301f228
commit 560597dcff
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
30 changed files with 117 additions and 323 deletions

View file

@ -48,7 +48,7 @@ class IndexCommandController extends CommandController
* *
* @param string $identifier * @param string $identifier
*/ */
public function indexCommand($identifier) public function indexCommand(string $identifier)
{ {
try { try {
$this->indexerFactory->getIndexer($identifier)->indexAllDocuments(); $this->indexerFactory->getIndexer($identifier)->indexAllDocuments();
@ -63,7 +63,7 @@ class IndexCommandController extends CommandController
* *
* @param string $identifier * @param string $identifier
*/ */
public function deleteCommand($identifier) public function deleteCommand(string $identifier)
{ {
try { try {
$this->indexerFactory->getIndexer($identifier)->delete(); $this->indexerFactory->getIndexer($identifier)->delete();

View file

@ -39,7 +39,6 @@ class ConfigurationContainer implements ConfigurationContainerInterface
/** /**
* Inject settings via ConfigurationManager. * Inject settings via ConfigurationManager.
* *
* @param ConfigurationManagerInterface $configurationManager
* @throws NoConfigurationException * @throws NoConfigurationException
*/ */
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
@ -59,7 +58,7 @@ class ConfigurationContainer implements ConfigurationContainerInterface
* @return mixed * @return mixed
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function get($path) public function get(string $path)
{ {
$value = ArrayUtility::getValueByPath($this->settings, $path); $value = ArrayUtility::getValueByPath($this->settings, $path);
@ -77,7 +76,7 @@ class ConfigurationContainer implements ConfigurationContainerInterface
* @param string $path In dot notation. * @param string $path In dot notation.
* @return mixed * @return mixed
*/ */
public function getIfExists($path) public function getIfExists(string $path)
{ {
return ArrayUtility::getValueByPath($this->settings, $path); return ArrayUtility::getValueByPath($this->settings, $path);
} }

View file

@ -37,7 +37,7 @@ interface ConfigurationContainerInterface extends Singleton
* *
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function get($path); public function get(string $path);
/** /**
* Same as get but will not throw an exception but return null. * Same as get but will not throw an exception but return null.
@ -45,5 +45,5 @@ interface ConfigurationContainerInterface extends Singleton
* @param string $path In dot notation. * @param string $path In dot notation.
* @return mixed|null * @return mixed|null
*/ */
public function getIfExists($path); public function getIfExists(string $path);
} }

View file

@ -28,62 +28,44 @@ interface ConnectionInterface
/** /**
* Will add a new document. * Will add a new document.
* *
* @param string $documentType
* @param array $document
*
* @return void * @return void
*/ */
public function addDocument($documentType, array $document); public function addDocument(string $documentType, array $document);
/** /**
* Add the given documents. * Add the given documents.
* *
* @param string $documentType
* @param array $documents
*
* @return void * @return void
*/ */
public function addDocuments($documentType, array $documents); public function addDocuments(string $documentType, array $documents);
/** /**
* Will update an existing document. * Will update an existing document.
* *
* NOTE: Batch updating is not yet supported. * NOTE: Batch updating is not yet supported.
* *
* @param string $documentType
* @param array $document
*
* @return void * @return void
*/ */
public function updateDocument($documentType, array $document); public function updateDocument(string $documentType, array $document);
/** /**
* Will remove an existing document. * Will remove an existing document.
* *
* NOTE: Batch deleting is not yet supported. * NOTE: Batch deleting is not yet supported.
* *
* @param string $documentType
* @param int $identifier
*
* @return void * @return void
*/ */
public function deleteDocument($documentType, $identifier); public function deleteDocument(string $documentType, string $identifier);
/** /**
* Search by given request and return result. * Search by given request and return result.
*
* @param SearchRequestInterface $searchRequest
*
* @return SearchResultInterface
*/ */
public function search(SearchRequestInterface $searchRequest); public function search(SearchRequestInterface $searchRequest) : SearchResultInterface;
/** /**
* Will delete the whole index / db. * Will delete the whole index / db.
* *
* @param string $documentType
*
* @return void * @return void
*/ */
public function deleteIndex($documentType); public function deleteIndex(string $documentType);
} }

View file

@ -112,7 +112,7 @@ class Elasticsearch implements Singleton, ConnectionInterface
$this->queryFactory = $queryFactory; $this->queryFactory = $queryFactory;
} }
public function addDocument($documentType, array $document) public function addDocument(string $documentType, array $document)
{ {
$this->withType( $this->withType(
$documentType, $documentType,
@ -122,7 +122,7 @@ class Elasticsearch implements Singleton, ConnectionInterface
); );
} }
public function deleteDocument($documentType, $identifier) public function deleteDocument(string $documentType, string $identifier)
{ {
try { try {
$this->withType( $this->withType(
@ -139,7 +139,7 @@ class Elasticsearch implements Singleton, ConnectionInterface
} }
} }
public function updateDocument($documentType, array $document) public function updateDocument(string $documentType, array $document)
{ {
$this->withType( $this->withType(
$documentType, $documentType,
@ -149,7 +149,7 @@ class Elasticsearch implements Singleton, ConnectionInterface
); );
} }
public function addDocuments($documentType, array $documents) public function addDocuments(string $documentType, array $documents)
{ {
$this->withType( $this->withType(
$documentType, $documentType,
@ -159,7 +159,7 @@ class Elasticsearch implements Singleton, ConnectionInterface
); );
} }
public function deleteIndex($documentType) public function deleteIndex(string $documentType)
{ {
$index = $this->connection->getClient()->getIndex('typo3content'); $index = $this->connection->getClient()->getIndex('typo3content');
@ -173,11 +173,8 @@ class Elasticsearch implements Singleton, ConnectionInterface
/** /**
* Execute given callback with Elastica Type based on provided documentType * Execute given callback with Elastica Type based on provided documentType
*
* @param string $documentType
* @param callable $callback
*/ */
protected function withType($documentType, callable $callback) protected function withType(string $documentType, callable $callback)
{ {
$type = $this->getType($documentType); $type = $this->getType($documentType);
// TODO: Check whether it's to heavy to send it so often e.g. for every single document. // TODO: Check whether it's to heavy to send it so often e.g. for every single document.
@ -191,12 +188,7 @@ class Elasticsearch implements Singleton, ConnectionInterface
$type->getIndex()->refresh(); $type->getIndex()->refresh();
} }
/** public function search(SearchRequestInterface $searchRequest) : SearchResultInterface
* @param SearchRequestInterface $searchRequest
*
* @return SearchResultInterface
*/
public function search(SearchRequestInterface $searchRequest)
{ {
$this->logger->debug('Search for', [$searchRequest->getSearchTerm()]); $this->logger->debug('Search for', [$searchRequest->getSearchTerm()]);
@ -207,12 +199,7 @@ class Elasticsearch implements Singleton, ConnectionInterface
return $this->objectManager->get(SearchResult::class, $searchRequest, $search->search()); return $this->objectManager->get(SearchResult::class, $searchRequest, $search->search());
} }
/** protected function getType(string $documentType) : \Elastica\Type
* @param string $documentType
*
* @return \Elastica\Type
*/
protected function getType($documentType)
{ {
return $this->typeFactory->getType( return $this->typeFactory->getType(
$this->indexFactory->getIndex( $this->indexFactory->getIndex(

View file

@ -52,9 +52,8 @@ class Connection implements Singleton
) { ) {
$this->configuration = $configuration; $this->configuration = $configuration;
$this->elasticaClient = $elasticaClient; if ($elasticaClient === null) {
if ($this->elasticaClient === null) { $elasticaClient = new \Elastica\Client([
$this->elasticaClient = new \Elastica\Client([
'host' => $this->configuration->get('connections.elasticsearch.host'), 'host' => $this->configuration->get('connections.elasticsearch.host'),
'port' => $this->configuration->get('connections.elasticsearch.port'), 'port' => $this->configuration->get('connections.elasticsearch.port'),
// TODO: Make configurable // TODO: Make configurable
@ -63,14 +62,13 @@ class Connection implements Singleton
// TODO: Make configurable. // TODO: Make configurable.
// new \Elastica\Log($this->elasticaClient); // new \Elastica\Log($this->elasticaClient);
} }
$this->elasticaClient = $elasticaClient;
} }
/** /**
* Get the concrete client for internal usage! * Get the concrete client for internal usage!
*
* @return \Elastica\Client
*/ */
public function getClient() public function getClient() : \ Elastica\Client
{ {
return $this->elasticaClient; return $this->elasticaClient;
} }

View file

@ -44,13 +44,8 @@ class DocumentFactory implements Singleton
/** /**
* Creates document from document. * Creates document from document.
*
* @param string $documentType
* @param array $document
*
* @return \Elastica\Document
*/ */
public function getDocument($documentType, array $document) public function getDocument(string $documentType, array $document) : \Elastica\Document
{ {
// TODO: Use DocumentType for further configuration. // TODO: Use DocumentType for further configuration.
@ -70,13 +65,8 @@ class DocumentFactory implements Singleton
/** /**
* Creates documents based on documents. * Creates documents based on documents.
*
* @param string $documentType
* @param array $documents
*
* @return array
*/ */
public function getDocuments($documentType, array $documents) public function getDocuments(string $documentType, array $documents) : array
{ {
foreach ($documents as &$document) { foreach ($documents as &$document) {
$document = $this->getDocument($documentType, $document); $document = $this->getDocument($documentType, $document);

View file

@ -22,6 +22,7 @@ namespace Codappix\SearchCore\Connection\Elasticsearch;
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface; use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
use Codappix\SearchCore\Connection\FacetInterface; use Codappix\SearchCore\Connection\FacetInterface;
use Codappix\SearchCore\Connection\FacetOptionInterface;
class Facet implements FacetInterface class Facet implements FacetInterface
{ {

View file

@ -43,18 +43,12 @@ class FacetOption implements FacetOptionInterface
$this->count = $bucket['doc_count']; $this->count = $bucket['doc_count'];
} }
/** public function getName() : string
* @return string
*/
public function getName()
{ {
return $this->name; return $this->name;
} }
/** public function getCount() : int
* @return int
*/
public function getCount()
{ {
return $this->count; return $this->count;
} }

View file

@ -49,13 +49,8 @@ class IndexFactory implements Singleton
/** /**
* Get an index bases on TYPO3 table name. * Get an index bases on TYPO3 table name.
*
* @param Connection $connection
* @param string $documentType
*
* @return \Elastica\Index
*/ */
public function getIndex(Connection $connection, $documentType) public function getIndex(Connection $connection, string $documentType) : \Elastica\Index
{ {
$index = $connection->getClient()->getIndex('typo3content'); $index = $connection->getClient()->getIndex('typo3content');
@ -66,12 +61,7 @@ class IndexFactory implements Singleton
return $index; return $index;
} }
/** protected function getConfigurationFor(string $documentType) : array
* @param string $documentType
*
* @return array
*/
protected function getConfigurationFor($documentType)
{ {
try { try {
$configuration = $this->configuration->get('indexing.' . $documentType . '.index'); $configuration = $this->configuration->get('indexing.' . $documentType . '.index');
@ -88,12 +78,7 @@ class IndexFactory implements Singleton
} }
} }
/** protected function prepareAnalyzerConfiguration(array $analyzer) : array
* @param array $analyzer
*
* @return array
*/
protected function prepareAnalyzerConfiguration(array $analyzer)
{ {
$fieldsToExplode = ['char_filter', 'filter']; $fieldsToExplode = ['char_filter', 'filter'];

View file

@ -44,12 +44,8 @@ class MappingFactory implements Singleton
/** /**
* Get an mapping based on type. * Get an mapping based on type.
*
* @param \Elastica\Type $type
*
* @return \Elastica\Mapping
*/ */
public function getMapping(\Elastica\Type $type) public function getMapping(\Elastica\Type $type) : \Elastica\Type\Mapping
{ {
$mapping = new \Elastica\Type\Mapping(); $mapping = new \Elastica\Type\Mapping();
$mapping->setType($type); $mapping->setType($type);
@ -64,11 +60,7 @@ class MappingFactory implements Singleton
return $mapping; return $mapping;
} }
/** protected function getConfiguration(string $identifier) : array
* @param string $identifier
* @return array
*/
protected function getConfiguration($identifier)
{ {
try { try {
return $this->configuration->get('indexing.' . $identifier . '.mapping'); return $this->configuration->get('indexing.' . $identifier . '.mapping');

View file

@ -77,7 +77,7 @@ class SearchResult implements SearchResultInterface
/** /**
* @return array<ResultItemInterface> * @return array<ResultItemInterface>
*/ */
public function getResults() public function getResults() : array
{ {
$this->initResults(); $this->initResults();
@ -89,14 +89,14 @@ class SearchResult implements SearchResultInterface
* *
* @return array<FacetInterface> * @return array<FacetInterface>
*/ */
public function getFacets() public function getFacets() : array
{ {
$this->initFacets(); $this->initFacets();
return $this->facets; return $this->facets;
} }
public function getCurrentCount() public function getCurrentCount() : int
{ {
return $this->result->count(); return $this->result->count();
} }

View file

@ -32,13 +32,8 @@ class TypeFactory implements Singleton
{ {
/** /**
* Get an index bases on TYPO3 table name. * Get an index bases on TYPO3 table name.
*
* @param \Elastica\Index $index
* @param string $documentType
*
* @return \Elastica\Type
*/ */
public function getType(\Elastica\Index $index, $documentType) public function getType(\Elastica\Index $index, string $documentType) : \Elastica\Type
{ {
return $index->getType($documentType); return $index->getType($documentType);
} }

View file

@ -25,15 +25,12 @@ namespace Codappix\SearchCore\Connection;
*/ */
interface FacetInterface interface FacetInterface
{ {
/** public function getName() : string;
* @return string
*/
public function getName();
/** /**
* Returns all possible options for this facet. * Returns all possible options for this facet.
* *
* @return array<FacetOptionInterface> * @return array<FacetOptionInterface>
*/ */
public function getOptions(); public function getOptions() : array;
} }

View file

@ -28,15 +28,11 @@ interface FacetOptionInterface
/** /**
* Returns the name of this option. Equivalent * Returns the name of this option. Equivalent
* to value used for filtering. * to value used for filtering.
*
* @return string
*/ */
public function getName(); public function getName() : string;
/** /**
* Returns the number of found results for this option. * Returns the number of found results for this option.
*
* @return int
*/ */
public function getCount(); public function getCount() : int;
} }

View file

@ -20,6 +20,8 @@ namespace Codappix\SearchCore\Connection;
* 02110-1301, USA. * 02110-1301, USA.
*/ */
use Codappix\SearchCore\Connection\ConnectionInterface;
use Codappix\SearchCore\Connection\FacetRequestInterface;
use Codappix\SearchCore\Domain\Search\SearchService; use Codappix\SearchCore\Domain\Search\SearchService;
use TYPO3\CMS\Extbase\Persistence\QueryInterface; use TYPO3\CMS\Extbase\Persistence\QueryInterface;
@ -27,20 +29,27 @@ interface SearchRequestInterface extends QueryInterface
{ {
/** /**
* Returns the actual string the user searched for. * Returns the actual string the user searched for.
*
* @return string
*/ */
public function getSearchTerm(); public function getSearchTerm() : string;
public function hasFilter() : bool;
public function getFilter() : array;
public function setFilter(array $filter);
public function addFacet(FacetRequestInterface $facet);
/** /**
* @return bool * @return array<FacetRequestInterface>
*/ */
public function hasFilter(); public function getFacets() : array;
/** /**
* @return array * Workaround for paginate widget support which will
* use the request to build another search.
*/ */
public function getFilter(); public function setConnection(ConnectionInterface $connection);
/** /**
* Workaround for paginate widget support which will * Workaround for paginate widget support which will

View file

@ -30,19 +30,17 @@ interface SearchResultInterface extends \Iterator, \Countable, QueryResultInterf
/** /**
* @return array<ResultItemInterface> * @return array<ResultItemInterface>
*/ */
public function getResults(); public function getResults() : array;
/** /**
* Return all facets, if any. * Return all facets, if any.
* *
* @return array<FacetInterface> * @return array<FacetInterface>
*/ */
public function getFacets(); public function getFacets() : array;
/** /**
* Returns the number of results in current result * Returns the number of results in current result
*
* @return int
*/ */
public function getCurrentCount(); public function getCurrentCount() : int;
} }

View file

@ -64,7 +64,7 @@ abstract class AbstractIndexer implements IndexerInterface
$this->logger = $logManager->getLogger(__CLASS__); $this->logger = $logManager->getLogger(__CLASS__);
} }
public function setIdentifier($identifier) public function setIdentifier(string $identifier)
{ {
$this->identifier = $identifier; $this->identifier = $identifier;
} }
@ -97,11 +97,11 @@ abstract class AbstractIndexer implements IndexerInterface
$this->logger->info('Finish indexing'); $this->logger->info('Finish indexing');
} }
public function indexDocument($identifier) public function indexDocument(string $identifier)
{ {
$this->logger->info('Start indexing single record.', [$identifier]); $this->logger->info('Start indexing single record.', [$identifier]);
try { try {
$record = $this->getRecord($identifier); $record = $this->getRecord((int) $identifier);
$this->prepareRecord($record); $this->prepareRecord($record);
$this->connection->addDocument($this->getDocumentName(), $record); $this->connection->addDocument($this->getDocumentName(), $record);
@ -119,10 +119,7 @@ abstract class AbstractIndexer implements IndexerInterface
$this->logger->info('Finish deletion.'); $this->logger->info('Finish deletion.');
} }
/** protected function getRecordGenerator() : \Generator
* @return \Generator
*/
protected function getRecordGenerator()
{ {
$offset = 0; $offset = 0;
$limit = $this->getLimit(); $limit = $this->getLimit();
@ -133,9 +130,6 @@ abstract class AbstractIndexer implements IndexerInterface
} }
} }
/**
* @param array &$record
*/
protected function prepareRecord(array &$record) protected function prepareRecord(array &$record)
{ {
try { try {
@ -149,9 +143,6 @@ abstract class AbstractIndexer implements IndexerInterface
$this->handleAbstract($record); $this->handleAbstract($record);
} }
/**
* @param array &$record
*/
protected function handleAbstract(array &$record) protected function handleAbstract(array &$record)
{ {
$record['search_abstract'] = ''; $record['search_abstract'] = '';
@ -177,31 +168,22 @@ abstract class AbstractIndexer implements IndexerInterface
/** /**
* Returns the limit to use to fetch records. * Returns the limit to use to fetch records.
*
* @return int
*/ */
protected function getLimit() protected function getLimit() : int
{ {
// TODO: Make configurable. // TODO: Make configurable.
return 50; return 50;
} }
/** /**
* @param int $offset
* @param int $limit
* @return array|null * @return array|null
*/ */
abstract protected function getRecords($offset, $limit); abstract protected function getRecords(int $offset, int $limit);
/** /**
* @param int $identifier
* @return array
* @throws NoRecordFoundException If record could not be found. * @throws NoRecordFoundException If record could not be found.
*/ */
abstract protected function getRecord($identifier); abstract protected function getRecord(int $identifier) : array;
/** abstract protected function getDocumentName() : string;
* @return string
*/
abstract protected function getDocumentName();
} }

View file

@ -56,12 +56,9 @@ class IndexerFactory implements Singleton
} }
/** /**
* @param string $identifier
*
* @return IndexerInterface
* @throws NoMatchingIndexer * @throws NoMatchingIndexer
*/ */
public function getIndexer($identifier) public function getIndexer(string $identifier) : IndexerInterface
{ {
try { try {
return $this->buildIndexer($this->configuration->get('indexing.' . $identifier . '.indexer'), $identifier); return $this->buildIndexer($this->configuration->get('indexing.' . $identifier . '.indexer'), $identifier);
@ -75,13 +72,9 @@ class IndexerFactory implements Singleton
} }
/** /**
* @param string $indexerClass
* @param string $identifier
*
* @return IndexerInterface
* @throws NoMatchingIndexer * @throws NoMatchingIndexer
*/ */
protected function buildIndexer($indexerClass, $identifier) protected function buildIndexer(string $indexerClass, string $identifier) : IndexerInterface
{ {
$indexer = null; $indexer = null;
if (is_subclass_of($indexerClass, TcaIndexer\PagesIndexer::class) if (is_subclass_of($indexerClass, TcaIndexer\PagesIndexer::class)

View file

@ -35,20 +35,16 @@ interface IndexerInterface
/** /**
* Fetches a single document and pushes it to the connection. * Fetches a single document and pushes it to the connection.
* *
* @param string $identifier
*
* @return void * @return void
*/ */
public function indexDocument($identifier); public function indexDocument(string $identifier);
/** /**
* Recieves the identifier of the indexer itself. * Recieves the identifier of the indexer itself.
* *
* @param string $identifier
*
* @return void * @return void
*/ */
public function setIdentifier($identifier); public function setIdentifier(string $identifier);
/** /**
* Delete the whole index. * Delete the whole index.

View file

@ -22,6 +22,7 @@ namespace Codappix\SearchCore\Domain\Index;
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface; use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
use Codappix\SearchCore\Connection\ConnectionInterface; use Codappix\SearchCore\Connection\ConnectionInterface;
use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableService;
use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
@ -46,17 +47,14 @@ class TcaIndexer extends AbstractIndexer
ConnectionInterface $connection, ConnectionInterface $connection,
ConfigurationContainerInterface $configuration ConfigurationContainerInterface $configuration
) { ) {
parent::__construct($connection, $configuration);
$this->tcaTableService = $tcaTableService; $this->tcaTableService = $tcaTableService;
$this->connection = $connection;
$this->configuration = $configuration;
} }
/** /**
* @param int $offset
* @param int $limit
* @return array|null * @return array|null
*/ */
protected function getRecords($offset, $limit) protected function getRecords(int $offset, int $limit)
{ {
$records = $this->getQuery() $records = $this->getQuery()
->setFirstResult($offset) ->setFirstResult($offset)
@ -77,14 +75,12 @@ class TcaIndexer extends AbstractIndexer
} }
/** /**
* @param int $identifier
* @return array
* @throws NoRecordFoundException If record could not be found. * @throws NoRecordFoundException If record could not be found.
*/ */
protected function getRecord($identifier) protected function getRecord(int $identifier) : array
{ {
$query = $this->getQuery(); $query = $this->getQuery();
$query = $query->andWhere($this->tcaTableService->getTableName() . '.uid = ' . (int) $identifier); $query = $query->andWhere($this->tcaTableService->getTableName() . '.uid = ' . $identifier);
$record = $query->execute()->fetch(); $record = $query->execute()->fetch();
if ($record === false || $record === null) { if ($record === false || $record === null) {
@ -98,15 +94,12 @@ class TcaIndexer extends AbstractIndexer
return $record; return $record;
} }
/** protected function getDocumentName() : string
* @return string
*/
protected function getDocumentName()
{ {
return $this->tcaTableService->getTableName(); return $this->tcaTableService->getTableName();
} }
protected function getQuery($tcaTableService = null) : QueryBuilder protected function getQuery(TcaTableService $tcaTableService = null) : QueryBuilder
{ {
if ($tcaTableService === null) { if ($tcaTableService === null) {
$tcaTableService = $this->tcaTableService; $tcaTableService = $this->tcaTableService;
@ -126,7 +119,7 @@ class TcaIndexer extends AbstractIndexer
return $query; return $query;
} }
protected function getDatabaseConnection() protected function getDatabaseConnection() : ConnectionPool
{ {
return GeneralUtility::makeInstance(ConnectionPool::class); return GeneralUtility::makeInstance(ConnectionPool::class);
} }

View file

@ -36,7 +36,7 @@ class PagesIndexer extends TcaIndexer
/** /**
* @param TcaTableService $tcaTableService * @param TcaTableService $tcaTableService
* @param TcaTableService $tcaTableService * @param TcaTableService $contentTableService
* @param ConnectionInterface $connection * @param ConnectionInterface $connection
* @param ConfigurationContainerInterface $configuration * @param ConfigurationContainerInterface $configuration
*/ */
@ -46,15 +46,10 @@ class PagesIndexer extends TcaIndexer
ConnectionInterface $connection, ConnectionInterface $connection,
ConfigurationContainerInterface $configuration ConfigurationContainerInterface $configuration
) { ) {
$this->tcaTableService = $tcaTableService; parent::__construct($tcaTableService, $connection, $configuration);
$this->contentTableService = $contentTableService; $this->contentTableService = $contentTableService;
$this->connection = $connection;
$this->configuration = $configuration;
} }
/**
* @param array &$record
*/
protected function prepareRecord(array &$record) protected function prepareRecord(array &$record)
{ {
$possibleTitleFields = ['nav_title', 'tx_tqseo_pagetitle_rel', 'title']; $possibleTitleFields = ['nav_title', 'tx_tqseo_pagetitle_rel', 'title'];
@ -69,11 +64,7 @@ class PagesIndexer extends TcaIndexer
parent::prepareRecord($record); parent::prepareRecord($record);
} }
/** protected function fetchContentForPage(int $uid) : string
* @param int $uid
* @return string
*/
protected function fetchContentForPage($uid)
{ {
$contentElements = $this->getQuery($this->contentTableService)->execute()->fetchAll(); $contentElements = $this->getQuery($this->contentTableService)->execute()->fetchAll();

View file

@ -107,17 +107,11 @@ class TcaTableService
$this->relationResolver = $relationResolver; $this->relationResolver = $relationResolver;
} }
/**
* @return string
*/
public function getTableName() : string public function getTableName() : string
{ {
return $this->tableName; return $this->tableName;
} }
/**
* @return string
*/
public function getTableClause() : string public function getTableClause() : string
{ {
return $this->tableName; return $this->tableName;
@ -125,9 +119,6 @@ class TcaTableService
/** /**
* Filter the given records by root line blacklist settings. * Filter the given records by root line blacklist settings.
*
* @param array &$records
* @return void
*/ */
public function filterRecordsByRootLineBlacklist(array &$records) public function filterRecordsByRootLineBlacklist(array &$records)
{ {
@ -139,9 +130,6 @@ class TcaTableService
); );
} }
/**
* @param array &$record
*/
public function prepareRecord(array &$record) public function prepareRecord(array &$record)
{ {
$this->relationResolver->resolveRelationsForRecord($this, $record); $this->relationResolver->resolveRelationsForRecord($this, $record);
@ -166,8 +154,8 @@ class TcaTableService
$whereClause .= ' AND ' . $userDefinedWhere; $whereClause .= ' AND ' . $userDefinedWhere;
} }
if ($this->isBlacklistedRootLineConfigured()) { if ($this->isBlackListedRootLineConfigured()) {
$parameters[':blacklistedRootLine'] = $this->getBlacklistedRootLine(); $parameters[':blacklistedRootLine'] = $this->getBlackListedRootLine();
$whereClause .= ' AND pages.uid NOT IN (:blacklistedRootLine)' $whereClause .= ' AND pages.uid NOT IN (:blacklistedRootLine)'
. ' AND pages.pid NOT IN (:blacklistedRootLine)'; . ' AND pages.pid NOT IN (:blacklistedRootLine)';
} }
@ -231,11 +219,7 @@ class TcaTableService
return $whereClause; return $whereClause;
} }
/** protected function isSystemField(string $columnName) : bool
* @param string
* @return bool
*/
protected function isSystemField($columnName) : bool
{ {
$systemFields = [ $systemFields = [
// Versioning fields, // Versioning fields,
@ -267,11 +251,9 @@ class TcaTableService
} }
/** /**
* @param string $columnName
* @return array
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function getColumnConfig($columnName) : array public function getColumnConfig(string $columnName) : array
{ {
if (!isset($this->tca['columns'][$columnName])) { if (!isset($this->tca['columns'][$columnName])) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
@ -290,9 +272,6 @@ class TcaTableService
* Also further TYPO3 mechanics are taken into account. Does a valid root * Also further TYPO3 mechanics are taken into account. Does a valid root
* line exist, is page inside a recycler, is inherited start- endtime * line exist, is page inside a recycler, is inherited start- endtime
* excluded, etc. * excluded, etc.
*
* @param array &$record
* @return bool
*/ */
protected function isRecordBlacklistedByRootline(array &$record) : bool protected function isRecordBlacklistedByRootline(array &$record) : bool
{ {
@ -348,8 +327,6 @@ class TcaTableService
/** /**
* Checks whether any page uids are black listed. * Checks whether any page uids are black listed.
*
* @return bool
*/ */
protected function isBlackListedRootLineConfigured() : bool protected function isBlackListedRootLineConfigured() : bool
{ {

View file

@ -72,56 +72,39 @@ class SearchRequest implements SearchRequestInterface
/** /**
* @param string $query * @param string $query
*/ */
public function __construct($query = '') public function __construct(string $query = '')
{ {
$this->query = (string) $query; $this->query = $query;
} }
/** public function getQuery() : string
* @return string
*/
public function getQuery()
{ {
return $this->query; return $this->query;
} }
/** public function getSearchTerm() : string
* @return string
*/
public function getSearchTerm()
{ {
return $this->query; return $this->query;
} }
/**
* @param array $filter
*/
public function setFilter(array $filter) public function setFilter(array $filter)
{ {
$filter = \TYPO3\CMS\Core\Utility\ArrayUtility::removeArrayEntryByValue($filter, ''); $filter = \TYPO3\CMS\Core\Utility\ArrayUtility::removeArrayEntryByValue($filter, '');
$this->filter = \TYPO3\CMS\Extbase\Utility\ArrayUtility::removeEmptyElementsRecursively($filter); $this->filter = \TYPO3\CMS\Extbase\Utility\ArrayUtility::removeEmptyElementsRecursively($filter);
} }
/** public function hasFilter() : bool
* @return bool
*/
public function hasFilter()
{ {
return count($this->filter) > 0; return count($this->filter) > 0;
} }
/** public function getFilter() : array
* @return array
*/
public function getFilter()
{ {
return $this->filter; return $this->filter;
} }
/** /**
* Add a facet to gather in this search request. * Add a facet to gather in this search request.
*
* @param FacetRequestInterface $facet
*/ */
public function addFacet(FacetRequestInterface $facet) public function addFacet(FacetRequestInterface $facet)
{ {
@ -130,10 +113,8 @@ class SearchRequest implements SearchRequestInterface
/** /**
* Returns all configured facets to fetch in this search request. * Returns all configured facets to fetch in this search request.
*
* @return array
*/ */
public function getFacets() public function getFacets() : array
{ {
return $this->facets; return $this->facets;
} }
@ -141,8 +122,6 @@ class SearchRequest implements SearchRequestInterface
/** /**
* Define connection to use for this request. * Define connection to use for this request.
* Necessary to allow implementation of execute for interface. * Necessary to allow implementation of execute for interface.
*
* @param ConnectionInterface $connection
*/ */
public function setConnection(ConnectionInterface $connection) public function setConnection(ConnectionInterface $connection)
{ {

View file

@ -62,7 +62,7 @@ class SearchResult implements SearchResultInterface
/** /**
* @return array<ResultItemInterface> * @return array<ResultItemInterface>
*/ */
public function getResults() public function getResults() : array
{ {
$this->initResults(); $this->initResults();
@ -80,12 +80,12 @@ class SearchResult implements SearchResultInterface
} }
} }
public function getFacets() public function getFacets() : array
{ {
return $this->originalSearchResult->getFacets(); return $this->originalSearchResult->getFacets();
} }
public function getCurrentCount() public function getCurrentCount() : int
{ {
return $this->originalSearchResult->getCurrentCount(); return $this->originalSearchResult->getCurrentCount();
} }

View file

@ -74,11 +74,7 @@ class SearchService
$this->dataProcessorService = $dataProcessorService; $this->dataProcessorService = $dataProcessorService;
} }
/** public function search(SearchRequestInterface $searchRequest) : SearchResultInterface
* @param SearchRequestInterface $searchRequest
* @return SearchResultInterface
*/
public function search(SearchRequestInterface $searchRequest)
{ {
$this->addSize($searchRequest); $this->addSize($searchRequest);
$this->addConfiguredFacets($searchRequest); $this->addConfiguredFacets($searchRequest);
@ -93,8 +89,6 @@ class SearchService
/** /**
* Add configured size of search result items to request. * Add configured size of search result items to request.
*
* @param SearchRequestInterface $searchRequest
*/ */
protected function addSize(SearchRequestInterface $searchRequest) protected function addSize(SearchRequestInterface $searchRequest)
{ {
@ -105,8 +99,6 @@ class SearchService
/** /**
* Add facets from configuration to request. * Add facets from configuration to request.
*
* @param SearchRequestInterface $searchRequest
*/ */
protected function addConfiguredFacets(SearchRequestInterface $searchRequest) protected function addConfiguredFacets(SearchRequestInterface $searchRequest)
{ {
@ -126,8 +118,6 @@ class SearchService
/** /**
* Add filters from configuration, e.g. flexform or TypoScript. * Add filters from configuration, e.g. flexform or TypoScript.
*
* @param SearchRequestInterface $searchRequest
*/ */
protected function addConfiguredFilters(SearchRequestInterface $searchRequest) protected function addConfiguredFilters(SearchRequestInterface $searchRequest)
{ {

View file

@ -22,6 +22,7 @@ namespace Codappix\SearchCore\Domain\Service;
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface; use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
use Codappix\SearchCore\Domain\Index\IndexerFactory; use Codappix\SearchCore\Domain\Index\IndexerFactory;
use Codappix\SearchCore\Domain\Index\IndexerInterface;
use Codappix\SearchCore\Domain\Index\NoMatchingIndexerException; use Codappix\SearchCore\Domain\Index\NoMatchingIndexerException;
use Codappix\SearchCore\Domain\Index\TcaIndexer; use Codappix\SearchCore\Domain\Index\TcaIndexer;
use TYPO3\CMS\Core\SingletonInterface as Singleton; use TYPO3\CMS\Core\SingletonInterface as Singleton;
@ -83,41 +84,27 @@ class DataHandler implements Singleton
$this->indexerFactory = $indexerFactory; $this->indexerFactory = $indexerFactory;
} }
/** public function update(string $table, array $record)
* @param string $table
*/
public function update($table, array $record)
{ {
$this->logger->debug('Record received for update.', [$table, $record]); $this->logger->debug('Record received for update.', [$table, $record]);
$this->getIndexer($table)->indexDocument($record['uid']); $this->getIndexer($table)->indexDocument($record['uid']);
} }
/** public function delete(string $table, string $identifier)
* @param string $table
* @param int $identifier
*/
public function delete($table, $identifier)
{ {
$this->logger->debug('Record received for delete.', [$table, $identifier]); $this->logger->debug('Record received for delete.', [$table, $identifier]);
$this->connection->deleteDocument($table, $identifier); $this->connection->deleteDocument($table, $identifier);
} }
/** /**
* @param string $table
* @return IndexerInterface
*
* @throws NoMatchingIndexerException * @throws NoMatchingIndexerException
*/ */
protected function getIndexer($table) protected function getIndexer(string $table) : IndexerInterface
{ {
return $this->indexerFactory->getIndexer($table); return $this->indexerFactory->getIndexer($table);
} }
/** public function canHandle(string $table) : bool
* @param string $table
* @return bool
*/
public function canHandle($table)
{ {
try { try {
$this->getIndexer($table); $this->getIndexer($table);

View file

@ -49,46 +49,38 @@ class DataHandler implements Singleton
/** /**
* Dependency injection as TYPO3 doesn't provide it on it's own. * Dependency injection as TYPO3 doesn't provide it on it's own.
* Still you can submit your own dataHandler. * Still you can submit your own dataHandler.
*
* @param OwnDataHandler $dataHandler
* @param Logger $logger
*/ */
public function __construct(OwnDataHandler $dataHandler = null, Logger $logger = null) public function __construct(OwnDataHandler $dataHandler = null, Logger $logger = null)
{ {
$this->dataHandler = $dataHandler; if ($dataHandler === null) {
if ($this->dataHandler === null) {
try { try {
$this->dataHandler = GeneralUtility::makeInstance(ObjectManager::class) $dataHandler = GeneralUtility::makeInstance(ObjectManager::class)
->get(OwnDataHandler::class); ->get(OwnDataHandler::class);
} catch (NoConfigurationException $e) { } catch (NoConfigurationException $e) {
// We have no configuration. That's fine, hooks will not be // We have no configuration. That's fine, hooks will not be
// executed due to check for existing DataHandler. // executed due to check for existing DataHandler.
} }
} }
$this->dataHandler = $dataHandler;
$this->logger = $logger; if ($logger === null) {
if ($this->logger === null) { $logger = GeneralUtility::makeInstance(LogManager::class)
$this->logger = GeneralUtility::makeInstance(LogManager::class)
->getLogger(__CLASS__); ->getLogger(__CLASS__);
} }
$this->logger = $logger;
} }
/** /**
* Called by CoreDataHandler on deletion of records. * Called by CoreDataHandler on deletion of records.
*
* @param string $table
* @param int $uid
*
* @return bool False if hook was not processed.
*/ */
public function processCmdmap_deleteAction($table, $uid) public function processCmdmap_deleteAction(string $table, int $uid) : bool
{ {
if (! $this->shouldProcessHookForTable($table)) { if (! $this->shouldProcessHookForTable($table)) {
$this->logger->debug('Delete not processed.', [$table, $uid]); $this->logger->debug('Delete not processed.', [$table, $uid]);
return false; return false;
} }
$this->dataHandler->delete($table, $uid); $this->dataHandler->delete($table, (string) $uid);
return true; return true;
} }
@ -125,11 +117,7 @@ class DataHandler implements Singleton
return false; return false;
} }
/** protected function shouldProcessHookForTable(string $table) : bool
* @param string $table
* @return bool
*/
protected function shouldProcessHookForTable($table)
{ {
if ($this->dataHandler === null) { if ($this->dataHandler === null) {
$this->logger->debug('Datahandler could not be setup.'); $this->logger->debug('Datahandler could not be setup.');
@ -146,11 +134,9 @@ class DataHandler implements Singleton
/** /**
* Wrapper to allow unit testing. * Wrapper to allow unit testing.
* *
* @param string $table * @return array|null
* @param int $uid
* @return null|array<String>
*/ */
protected function getRecord($table, $uid) protected function getRecord(string $table, int $uid)
{ {
return BackendUtility::getRecord($table, $uid); return BackendUtility::getRecord($table, $uid);
} }

View file

@ -62,7 +62,7 @@ class DataHandlerFinisher extends AbstractFinisher
$this->dataHandler->update($tableName, $record); $this->dataHandler->update($tableName, $record);
break; break;
case 'delete': case 'delete':
$this->dataHandler->delete($tableName, $record['uid']); $this->dataHandler->delete($tableName, (string) $record['uid']);
break; break;
} }
} }

View file

@ -29,10 +29,7 @@ use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
*/ */
class FrontendUtility extends BackendUtility class FrontendUtility extends BackendUtility
{ {
/** protected static function getLanguageService() : TypoScriptFrontendController
* @return TypoScriptFrontendController
*/
protected static function getLanguageService()
{ {
return $GLOBALS['TSFE']; return $GLOBALS['TSFE'];
} }