Skip to content

Commit

Permalink
Merge pull request #46 from kdambekalns/cleanup
Browse files Browse the repository at this point in the history
TASK: Clean up code and tests

This does some code style cleanup, fixes type hints and adjusts the code in two places:

- indexing skips non-gettable properties now
- no longer use deprecated `getClassNameByObject`

The latter makes this package depend on Flow 3.0 or higher.

Also, the package now contains a LICENSE file (MIT license).
  • Loading branch information
kdambekalns authored Jul 11, 2016
2 parents 919652e + 402dd6d commit 9861438
Show file tree
Hide file tree
Showing 30 changed files with 188 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class IndexCommandController extends \TYPO3\Flow\Cli\CommandController
*
* @param string $indexName The name of the new index
* @param string $clientName The client name to use
* @return void
*/
public function createCommand($indexName, $clientName = null)
{
Expand Down Expand Up @@ -84,6 +85,7 @@ public function createCommand($indexName, $clientName = null)
*
* @param string $indexName The name of the new index
* @param string $clientName The client name to use
* @return void
*/
public function updateSettingsCommand($indexName, $clientName = null)
{
Expand Down Expand Up @@ -112,6 +114,7 @@ public function updateSettingsCommand($indexName, $clientName = null)
*
* @param string $indexName The name of the index to be removed
* @param string $clientName The client name to use
* @return void
*/
public function deleteCommand($indexName, $clientName = null)
{
Expand Down Expand Up @@ -140,6 +143,7 @@ public function deleteCommand($indexName, $clientName = null)
*
* @param string $indexName The name of the index to be removed
* @param string $clientName The client name to use
* @return void
*/
public function refreshCommand($indexName, $clientName = null)
{
Expand All @@ -164,6 +168,8 @@ public function refreshCommand($indexName, $clientName = null)

/**
* List available document type
*
* @return void
*/
public function showConfiguredTypesCommand()
{
Expand All @@ -181,6 +187,7 @@ public function showConfiguredTypesCommand()
* @param string $object Class name of a domain object. If given, will only work on this single object
* @param boolean $conductUpdate Set to TRUE to conduct the required corrections
* @param string $clientName The client name to use
* @return void
*/
public function statusCommand($object = null, $conductUpdate = false, $clientName = null)
{
Expand Down Expand Up @@ -258,7 +265,6 @@ public function statusCommand($object = null, $conductUpdate = false, $clientNam
/**
* @param Client $client
* @param string $className
*
* @return array
*/
protected function getModificationsNeededStatesAndIdentifiers(Client $client, $className)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* source code.
*/

use Flowpack\ElasticSearch\Mapping\MappingCollection;
use TYPO3\Flow\Annotations as Flow;

/**
Expand Down Expand Up @@ -178,11 +179,11 @@ protected function markupDiffValue($entityValue, $backendValue)
/**
* Traverses through mappingInformation array and aggregates by index and type names
*
* @param \Flowpack\ElasticSearch\Mapping\MappingCollection $mappingCollection
* @param MappingCollection $mappingCollection
* @throws \Flowpack\ElasticSearch\Exception
* @return array with index names as keys, second level type names as keys
*/
protected function buildArrayFromMappingCollection(\Flowpack\ElasticSearch\Mapping\MappingCollection $mappingCollection)
protected function buildArrayFromMappingCollection(MappingCollection $mappingCollection)
{
$return = array();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@
* source code.
*/

use TYPO3\Flow\Error\Result;

/**
* Signals a mismatch between the
*/
class DocumentPropertiesMismatchException extends \Flowpack\ElasticSearch\Exception
{
/**
* @var \TYPO3\Flow\Error\Result
* @var Result
*/
protected $errorResult;

/**
* @param \TYPO3\Flow\Error\Result $result
* @param Result $result
* @return void
*/
public function setErrorResult(\TYPO3\Flow\Error\Result $result)
public function setErrorResult(Result $result)
{
$this->errorResult = $result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function injectSettings(array $settings)
* @param string $clientClassName
* @throws \Flowpack\ElasticSearch\Exception
* @return \Flowpack\ElasticSearch\Domain\Model\Client
* @return void
*/
public function create($bundle = null, $clientClassName = 'Flowpack\ElasticSearch\Domain\Model\Client')
{
Expand All @@ -59,12 +60,11 @@ public function create($bundle = null, $clientClassName = 'Flowpack\ElasticSearc
}

/**
* @param $clientsSettings
*
* @param array $clientsSettings
* @return array
* @throws \Flowpack\ElasticSearch\Exception
*/
protected function buildClientConfigurations($clientsSettings)
protected function buildClientConfigurations(array $clientsSettings)
{
$clientConfigurations = array();
foreach ($clientsSettings as $clientSettings) {
Expand Down
8 changes: 3 additions & 5 deletions Classes/Flowpack/ElasticSearch/Domain/Model/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public function getIndex()
/**
* Returns a document
*
* @param $id
*
* @param string $id
* @return \Flowpack\ElasticSearch\Domain\Model\Document
*/
public function findDocumentById($id)
Expand All @@ -86,7 +85,7 @@ public function findDocumentById($id)
}

/**
* @param $id
* @param string $id
* @return boolean ...whether the deletion is considered successful
*/
public function deleteDocumentById($id)
Expand Down Expand Up @@ -125,10 +124,9 @@ public function search(array $searchQuery)
* @param string $path
* @param array $arguments
* @param string $content
*
* @return \Flowpack\ElasticSearch\Transfer\Response
*/
public function request($method, $path = null, $arguments = array(), $content = null)
public function request($method, $path = null, array $arguments = array(), $content = null)
{
$path = '/' . $this->name . ($path ?: '');

Expand Down
3 changes: 1 addition & 2 deletions Classes/Flowpack/ElasticSearch/Domain/Model/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ public function findIndex($indexName)
* @param string $path
* @param array $arguments
* @param string|array $content
*
* @return \Flowpack\ElasticSearch\Transfer\Response
*/
public function request($method, $path = null, $arguments = array(), $content = null)
public function request($method, $path = null, array $arguments = array(), $content = null)
{
return $this->requestService->request($method, $this, $path, $arguments, $content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ClientConfiguration

/**
* @param string $host
* @return void
*/
public function setHost($host)
{
Expand All @@ -61,6 +62,7 @@ public function getHost()

/**
* @param int $port
* @return void
*/
public function setPort($port)
{
Expand All @@ -77,6 +79,7 @@ public function getPort()

/**
* @param string $scheme
* @return void
*/
public function setScheme($scheme)
{
Expand Down
18 changes: 10 additions & 8 deletions Classes/Flowpack/ElasticSearch/Domain/Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class Document
{
/**
* @var \Flowpack\ElasticSearch\Domain\Model\AbstractType
* @var AbstractType
*/
protected $type;

Expand Down Expand Up @@ -52,10 +52,10 @@ class Document
protected $dirty = true;

/**
* @param \Flowpack\ElasticSearch\Domain\Model\AbstractType $type
* @param AbstractType $type
* @param array $data
* @param string $id
* @param null $version
* @param integer $version
*/
public function __construct(AbstractType $type, array $data = null, $id = null, $version = null)
{
Expand All @@ -68,6 +68,8 @@ public function __construct(AbstractType $type, array $data = null, $id = null,
/**
* When cloning (locally), the cloned object doesn't represent a stored one anymore,
* so reset id, version and the dirty state.
*
* @return void
*/
public function __clone()
{
Expand All @@ -81,10 +83,9 @@ public function __clone()
* @param string $path
* @param array $arguments
* @param string $content
*
* @return \Flowpack\ElasticSearch\Transfer\Response
*/
protected function request($method, $path = null, $arguments = array(), $content = null)
protected function request($method, $path = null, array $arguments = array(), $content = null)
{
return $this->type->request($method, $path, $arguments, $content);
}
Expand Down Expand Up @@ -114,6 +115,7 @@ public function store()

/**
* @param boolean $dirty
* @return void
*/
protected function setDirty($dirty = true)
{
Expand Down Expand Up @@ -148,8 +150,9 @@ public function getData()

/**
* @param array $data
* @return void
*/
public function setData($data)
public function setData(array $data)
{
$this->data = $data;
$this->setDirty();
Expand All @@ -168,7 +171,6 @@ public function getId()
*
* @param string $fieldName
* @param boolean $silent
*
* @throws \Flowpack\ElasticSearch\Exception
* @return mixed
*/
Expand All @@ -182,7 +184,7 @@ public function getField($fieldName, $silent = false)
}

/**
* @return \Flowpack\ElasticSearch\Domain\Model\AbstractType the type of this Document
* @return AbstractType the type of this Document
*/
public function getType()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class GenericType extends AbstractType
{
/**
* @param \Flowpack\ElasticSearch\Domain\Model\Index $index
* @param Index $index
* @param string $name
*/
public function __construct(Index $index, $name)
Expand Down
13 changes: 6 additions & 7 deletions Classes/Flowpack/ElasticSearch/Domain/Model/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public function injectSettings(array $settings)
/**
* @param $name
* @param Client $client $client
*
* @throws \Flowpack\ElasticSearch\Exception
*/
public function __construct($name, Client $client = null)
Expand All @@ -113,7 +112,7 @@ public function __construct($name, Client $client = null)
}

/**
* @param $typeName
* @param string $typeName
* @return \Flowpack\ElasticSearch\Domain\Model\AbstractType
*/
public function findType($typeName)
Expand All @@ -123,7 +122,6 @@ public function findType($typeName)

/**
* @param array<AbstractType> $types
*
* @return TypeGroup
*/
public function findTypeGroup(array $types)
Expand Down Expand Up @@ -189,11 +187,10 @@ public function refresh()
* @param array $arguments
* @param string $content
* @param boolean $prefixIndex
*
* @throws \Flowpack\ElasticSearch\Exception
* @return \Flowpack\ElasticSearch\Transfer\Response
* @throws \Flowpack\ElasticSearch\Exception
*/
public function request($method, $path = null, $arguments = array(), $content = null, $prefixIndex = true)
public function request($method, $path = null, array $arguments = array(), $content = null, $prefixIndex = true)
{
if ($this->client === null) {
throw new Exception('The client of the index "' . $this->name . '" is not set, hence no requests can be done.');
Expand All @@ -218,14 +215,16 @@ public function getName()

/**
* @param Client $client
* @return void
*/
public function setClient($client)
{
$this->client = $client;
}

/**
* @param $settingsKey
* @param string $settingsKey
* @return void
*/
public function setSettingsKey($settingsKey)
{
Expand Down
Loading

0 comments on commit 9861438

Please sign in to comment.