Feature/improve scrutinizer (#3)

* TASK: Fix scrutinizer issues

* TASK: Add library dependency

* FIX: Adjust php and TYPO3 requirements

* TASK: Adjust test
This commit is contained in:
Daniel Siepmann 2016-12-09 14:07:38 +01:00 committed by GitHub
parent b079dd8125
commit e75f24092e
16 changed files with 96 additions and 102 deletions

View file

@ -1,9 +1,11 @@
filter: filter:
excluded_paths: excluded_paths:
- 'Configuration/*'
- 'Documentation/*' - 'Documentation/*'
- 'Resources/JavaScript/*' - 'Resources/*'
paths: paths:
- 'Classes/*' - 'Classes/*'
- 'Tests/*'
tools: tools:
php_cpd: php_cpd:

View file

@ -26,49 +26,50 @@ namespace Leonmrni\SearchCore\Connection;
interface ConnectionInterface interface ConnectionInterface
{ {
/** /**
* Will add a new document, based on his identifier and record type. * Will add a new document.
* *
* @param string $recordType * @param string $documentType
* @param int $identifier * @param array $document
* @param array $record
* *
* @return * @return void
*/ */
public function add($recordType, $identifier, array $record); public function add($documentType, array $document);
/** /**
* Add the given records. * Add the given documents.
* *
* @param string $recordType * @param string $documentType
* @param array $records * @param array $documents
*
* @return void
*/ */
public function addDocuments($recordType, array $records); public function addDocuments($documentType, array $documents);
/** /**
* Will update an existing document, based on his identifier and record type. * Will update an existing document.
* *
* @param string $recordType * @param string $documentType
* @param int $identifier * @param array $document
* @param array $record
* *
* @return * @return void
*/ */
public function update($recordType, $identifier, array $record); public function update($documentType, array $document);
/** /**
* Will remove an existing document, based on his identifier and record type. * Will remove an existing document.
* *
* @param string $recordType * @param string $documentType
* @param int $identifier * @param int $identifier
* *
* @return * @return void
*/ */
public function delete($recordType, $identifier); public function delete($documentType, $identifier);
/** /**
* Search by given request and return result. * Search by given request and return result.
* *
* @param SearchRequestInterface $searchRequest * @param SearchRequestInterface $searchRequest
*
* @return SearchResultInterface * @return SearchResultInterface
*/ */
public function search(SearchRequestInterface $searchRequest); public function search(SearchRequestInterface $searchRequest);

View file

@ -33,17 +33,17 @@ class Elasticsearch implements Singleton, ConnectionInterface
protected $connection; protected $connection;
/** /**
* @var IndexFactory * @var Elasticsearch\IndexFactory
*/ */
protected $indexFactory; protected $indexFactory;
/** /**
* @var TypeFactory * @var Elasticsearch\TypeFactory
*/ */
protected $typeFactory; protected $typeFactory;
/** /**
* @var DocumentFactory * @var Elasticsearch\DocumentFactory
*/ */
protected $documentFactory; protected $documentFactory;
@ -80,44 +80,39 @@ class Elasticsearch implements Singleton, ConnectionInterface
$this->documentFactory = $documentFactory; $this->documentFactory = $documentFactory;
} }
public function add($recordType, $identifier, array $record) public function add($documentType, array $document)
{ {
throw new \Exception('Implement', 1481190734); throw new \Exception('Implement', 1481190734);
} }
public function delete($recordType, $identifier) public function delete($documentType, $identifier)
{ {
throw new \Exception('Implement', 1481190734); throw new \Exception('Implement', 1481190734);
} }
public function update($tableName, $identifier, array $record) public function update($documentType, array $document)
{ {
$this->addDocument($tableName, $identifier, $record); throw new \Exception('Implement', 1481190734);
}
protected function addDocument($tableName, $identifier, array $record)
{
throw new \Exception('Implement', 1481192791);
} }
/** /**
* Add the given records to elasticsearch. * Add the given documents to elasticsearch.
* *
* @param string $tableName * @param string $documentType
* @param array $records * @param array $documents
*/ */
public function addDocuments($tableName, array $records) public function addDocuments($documentType, array $documents)
{ {
$type = $this->typeFactory->getType( $type = $this->typeFactory->getType(
$this->indexFactory->getIndex( $this->indexFactory->getIndex(
$this->connection, $this->connection,
$tableName $documentType
), ),
$tableName $documentType
); );
$type->addDocuments( $type->addDocuments(
$this->documentFactory->getDocuments($tableName, $records) $this->documentFactory->getDocuments($documentType, $documents)
); );
$type->getIndex()->refresh(); $type->getIndex()->refresh();

View file

@ -43,40 +43,42 @@ class DocumentFactory implements Singleton
} }
/** /**
* Creates document from record. * Creates document from document.
* *
* @param string $tableName * @param string $documentType
* @param array $record * @param array $document
* *
* @return \Elastica\Document * @return \Elastica\Document
*/ */
public function getDocument($tableName, array $record) public function getDocument($documentType, array $document)
{ {
if (!isset($record['search_identifier'])) { // TODO: Use DocumentType for further configuration.
throw new \Exception('No search_identifier provided for record.', 1481194385);
if (!isset($document['search_identifier'])) {
throw new \Exception('No search_identifier provided for document.', 1481194385);
} }
$identifier = $record['search_identifier']; $identifier = $document['search_identifier'];
unset($record['search_identifier']); unset($document['search_identifier']);
$this->logger->debug('Convert record to document', [$identifier, $record]); $this->logger->debug('Convert document to document', [$identifier, $document]);
return new \Elastica\Document($identifier, $record); return new \Elastica\Document($identifier, $document);
} }
/** /**
* Creates documents based on records. * Creates documents based on documents.
* *
* @param string $tableName * @param string $documentType
* @param array $records * @param array $documents
* *
* @return array * @return array
*/ */
public function getDocuments($tableName, array $records) public function getDocuments($documentType, array $documents)
{ {
foreach ($records as &$record) { foreach ($documents as &$document) {
$record = $this->getDocument($tableName, $record); $document = $this->getDocument($documentType, $document);
} }
return $records; return $documents;
} }
} }

View file

@ -20,6 +20,7 @@ namespace Leonmrni\SearchCore\Connection\Elasticsearch;
* 02110-1301, USA. * 02110-1301, USA.
*/ */
use Elastica\Exception\ResponseException;
use TYPO3\CMS\Core\SingletonInterface as Singleton; use TYPO3\CMS\Core\SingletonInterface as Singleton;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
@ -34,20 +35,20 @@ class IndexFactory implements Singleton
* Get an index bases on TYPO3 table name. * Get an index bases on TYPO3 table name.
* *
* @param Connection $connection * @param Connection $connection
* @param string $tableName * @param string $documentType
* *
* @return \Elastica\Index * @return \Elastica\Index
*/ */
public function getIndex(Connection $connection, $tableName) public function getIndex(Connection $connection, $documentType)
{ {
// TODO: Fetch index name from configuration, based on $tableName. // TODO: Fetch index name from configuration, based on $documentType.
$index = $connection->getClient()->getIndex('typo3content'); $index = $connection->getClient()->getIndex('typo3content');
try { try {
// TODO: Provide configuration?! // TODO: Provide configuration?!
// http://elastica.io/getting-started/storing-and-indexing-documents.html#section-analysis // http://elastica.io/getting-started/storing-and-indexing-documents.html#section-analysis
$index->create(); $index->create();
} catch (\Elastica\Exception\ResponseException $exception) { } catch (ResponseException $exception) {
if (stripos($exception->getMessage(), 'already exists') === false) { if (stripos($exception->getMessage(), 'already exists') === false) {
throw $exception; throw $exception;
} }

View file

@ -34,12 +34,12 @@ 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 \Elastica\Index $index
* @param string $tableName * @param string $documentType
* *
* @return \Elastica\Type * @return \Elastica\Type
*/ */
public function getType(\Elastica\Index $index, $tableName) public function getType(\Elastica\Index $index, $documentType)
{ {
return $index->getType($tableName); return $index->getType($documentType);
} }
} }

View file

@ -47,7 +47,7 @@ class SearchController extends ActionController
/** /**
* Process a search and deliver original request and result to view. * Process a search and deliver original request and result to view.
* *
* @param SearchRequest $searchRequest * @param null|SearchRequest $searchRequest
*/ */
public function searchAction(SearchRequest $searchRequest = null) public function searchAction(SearchRequest $searchRequest = null)
{ {

View file

@ -29,7 +29,7 @@ use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
class IndexerFactory implements Singleton class IndexerFactory implements Singleton
{ {
/** /**
* @var ObjectManager * @var ObjectManagerInterface
*/ */
protected $objectManager; protected $objectManager;

View file

@ -27,6 +27,8 @@ interface IndexerInterface
{ {
/** /**
* Index the index. * Index the index.
*
* @return void
*/ */
public function index(); public function index();
} }

View file

@ -54,7 +54,7 @@ class TcaIndexer implements IndexerInterface
} }
/** /**
* @param string $tableName * @param TcaIndexer\TcaTableService $tcaTableService
* @param ConnectionInterface $connection * @param ConnectionInterface $connection
*/ */
public function __construct( public function __construct(
@ -76,7 +76,7 @@ class TcaIndexer implements IndexerInterface
} }
/** /**
* @return \Iterator * @return \Generator
*/ */
protected function getRecordGenerator() protected function getRecordGenerator()
{ {

View file

@ -132,11 +132,7 @@ class TcaTableService
*/ */
protected function isRelation(array &$columnConfig) protected function isRelation(array &$columnConfig)
{ {
if (isset($columnConfig['foreign_table'])) { return isset($columnConfig['foreign_table']);
return true;
}
return false;
} }
/** /**
@ -158,10 +154,7 @@ class TcaTableService
$this->tca['ctrl']['languageField'], $this->tca['ctrl']['languageField'],
$this->tca['ctrl']['origUid'], $this->tca['ctrl']['origUid'],
]; ];
if (in_array($columnName, $systemFields)) {
return true;
}
return false; return in_array($columnName, $systemFields);
} }
} }

View file

@ -63,22 +63,20 @@ class DataHandler implements Singleton
/** /**
* @param string $table * @param string $table
* @param int $identifier
* @param array $record * @param array $record
*/ */
public function add($table, $identifier, array $record) public function add($table, array $record)
{ {
$this->logger->debug('Record received for add.', [$table, $identifier, $record]); $this->logger->debug('Record received for add.', [$table, $record]);
$this->connection->add($table, $identifier, $record); $this->connection->add($table, $record);
} }
/** /**
* @param string $table * @param string $table
* @param int $identifier
*/ */
public function update($table, $identifier, array $record) public function update($table, array $record)
{ {
$this->logger->debug('Record received for update.', [$table, $identifier, $record]); $this->logger->debug('Record received for update.', [$table, $record]);
$this->connection->update($table, $identifier, $record); $this->connection->update($table, $record);
} }
} }

View file

@ -74,11 +74,8 @@ class DataHandler implements Singleton
* *
* @param string $table * @param string $table
* @param int $uid * @param int $uid
* @param array $record
* @param bool $recordWasDeleted
* @param CoreDataHandler $dataHandler
*/ */
public function processCmdmap_deleteAction($table, $uid, array $record, $recordWasDeleted, CoreDataHandler $dataHandler) public function processCmdmap_deleteAction($table, $uid)
{ {
if (! $this->shouldProcessTable($table)) { if (! $this->shouldProcessTable($table)) {
$this->logger->debug('Delete not processed, cause table is not allowed.', [$table]); $this->logger->debug('Delete not processed, cause table is not allowed.', [$table]);
@ -105,20 +102,23 @@ class DataHandler implements Singleton
} }
if ($status === 'new') { if ($status === 'new') {
$this->dataHandler->add($table, $dataHandler->substNEWwithIDs[$uid], $fieldArray); $fieldArray['uid'] = $dataHandler->substNEWwithIDs[$uid];
$this->dataHandler->add($table, $fieldArray);
return; return;
} }
if ($status === 'update') { if ($status === 'update') {
$this->dataHandler->update( $record = $this->getRecord($table, $uid);
$table, if ($record !== null) {
$uid, $this->dataHandler->update($table, $record);
$this->getRecord($table, $uid) }
);
return; return;
} }
$this->logger->debug('Database update not processed, cause status is unhandled.', [$status, $table, $uid, $fieldArray]); $this->logger->debug(
'Database update not processed, cause status is unhandled.',
[$status, $table, $uid, $fieldArray]
);
} }
/** /**
@ -126,7 +126,7 @@ class DataHandler implements Singleton
* *
* TODO: Fetch from config * TODO: Fetch from config
* *
* @return array * @return string[]
*/ */
protected function getTablesToProcess() protected function getTablesToProcess()
{ {
@ -149,7 +149,7 @@ class DataHandler implements Singleton
* *
* @param string $table * @param string $table
* @param int $uid * @param int $uid
* @return array * @return null|array
*/ */
protected function getRecord($table, $uid) protected function getRecord($table, $uid)
{ {

View file

@ -134,7 +134,6 @@ class DataHandlerTest extends UnitTestCase
->method('update') ->method('update')
->with( ->with(
$this->equalTo($table), $this->equalTo($table),
$this->equalTo($recordUid),
$this->equalTo($record) $this->equalTo($record)
); );

View file

@ -17,7 +17,8 @@
}, },
"require" : { "require" : {
"php": ">=5.6.0", "php": ">=5.6.0",
"typo3/cms": ">=6.2.0" "typo3/cms": ">=6.2.0",
"ruflin/elastica": "~1.4"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.8.0" "phpunit/phpunit": "~4.8.0"

View file

@ -6,8 +6,8 @@ $EM_CONF[$_EXTKEY] = [
'category' => 'be', 'category' => 'be',
'constraints' => [ 'constraints' => [
'depends' => [ 'depends' => [
'typo3' => '7.6.2-8.99.99', 'typo3' => '6.2.0-8.99.99',
'php' => '7.0.0-7.99.99' 'php' => '5.6.0-7.99.99'
], ],
'conflicts' => [], 'conflicts' => [],
], ],