Skip to content

Commit

Permalink
Typehinted Bulk namespace (#1550)
Browse files Browse the repository at this point in the history
  • Loading branch information
massimilianobraglia authored and p365labs committed Feb 7, 2019
1 parent 6ae6e16 commit 8a432f7
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 143 deletions.
4 changes: 2 additions & 2 deletions lib/Elastica/AbstractUpdateAction.php
Expand Up @@ -18,7 +18,7 @@ class AbstractUpdateAction extends Param
/**
* Sets the id of the document.
*
* @param string $id
* @param string|int $id
*
* @return $this
*/
Expand All @@ -34,7 +34,7 @@ public function setId($id)
*/
public function getId()
{
return ($this->hasParam('_id')) ? $this->getParam('_id') : null;
return $this->hasParam('_id') ? $this->getParam('_id') : null;
}

/**
Expand Down
89 changes: 45 additions & 44 deletions lib/Elastica/Bulk.php
Expand Up @@ -6,6 +6,7 @@
use Elastica\Bulk\Action\AbstractDocument as AbstractDocumentAction;
use Elastica\Bulk\Response as BulkResponse;
use Elastica\Bulk\ResponseSet;
use Elastica\Exception\Bulk\ResponseException;
use Elastica\Exception\Bulk\ResponseException as BulkResponseException;
use Elastica\Exception\InvalidException;
use Elastica\Script\AbstractScript;
Expand All @@ -15,12 +16,12 @@ class Bulk
const DELIMITER = "\n";

/**
* @var \Elastica\Client
* @var Client
*/
protected $_client;

/**
* @var \Elastica\Bulk\Action[]
* @var Action[]
*/
protected $_actions = [];

Expand All @@ -40,19 +41,19 @@ class Bulk
protected $_requestParams = [];

/**
* @param \Elastica\Client $client
* @param Client $client
*/
public function __construct(Client $client)
{
$this->_client = $client;
}

/**
* @param string|\Elastica\Index $index
* @param string|Index $index
*
* @return $this
*/
public function setIndex($index)
public function setIndex($index): self
{
if ($index instanceof Index) {
$index = $index->getName();
Expand All @@ -74,17 +75,17 @@ public function getIndex()
/**
* @return bool
*/
public function hasIndex()
public function hasIndex(): bool
{
return null !== $this->getIndex() && '' !== $this->getIndex();
}

/**
* @param string|\Elastica\Type $type
* @param string|Type $type
*
* @return $this
*/
public function setType($type)
public function setType($type): self
{
if ($type instanceof Type) {
$this->setIndex($type->getIndex()->getName());
Expand All @@ -107,15 +108,15 @@ public function getType()
/**
* @return bool
*/
public function hasType()
public function hasType(): bool
{
return null !== $this->getType() && '' !== $this->getType();
}

/**
* @return string
*/
public function getPath()
public function getPath(): string
{
$path = '';
if ($this->hasIndex()) {
Expand All @@ -130,23 +131,23 @@ public function getPath()
}

/**
* @param \Elastica\Bulk\Action $action
* @param Action $action
*
* @return $this
*/
public function addAction(Action $action)
public function addAction(Action $action): self
{
$this->_actions[] = $action;

return $this;
}

/**
* @param \Elastica\Bulk\Action[] $actions
* @param Action[] $actions
*
* @return $this
*/
public function addActions(array $actions)
public function addActions(array $actions): self
{
foreach ($actions as $action) {
$this->addAction($action);
Expand All @@ -156,33 +157,33 @@ public function addActions(array $actions)
}

/**
* @return \Elastica\Bulk\Action[]
* @return Action[]
*/
public function getActions()
public function getActions(): array
{
return $this->_actions;
}

/**
* @param \Elastica\Document $document
* @param string $opType
* @param Document $document
* @param string $opType
*
* @return $this
*/
public function addDocument(Document $document, $opType = null)
public function addDocument(Document $document, string $opType = null): self
{
$action = AbstractDocumentAction::create($document, $opType);

return $this->addAction($action);
}

/**
* @param \Elastica\Document[] $documents
* @param string $opType
* @param Document[] $documents
* @param string $opType
*
* @return $this
*/
public function addDocuments(array $documents, $opType = null)
public function addDocuments(array $documents, string $opType = null): self
{
foreach ($documents as $document) {
$this->addDocument($document, $opType);
Expand All @@ -192,25 +193,25 @@ public function addDocuments(array $documents, $opType = null)
}

/**
* @param \Elastica\Script\AbstractScript $script
* @param string $opType
* @param AbstractScript $script
* @param string $opType
*
* @return $this
*/
public function addScript(AbstractScript $script, $opType = null)
public function addScript(AbstractScript $script, string $opType = null): self
{
$action = AbstractDocumentAction::create($script, $opType);

return $this->addAction($action);
}

/**
* @param \Elastica\Document[] $scripts
* @param string $opType
* @param Document[] $scripts
* @param string $opType
*
* @return $this
*/
public function addScripts(array $scripts, $opType = null)
public function addScripts(array $scripts, $opType = null): self
{
foreach ($scripts as $document) {
$this->addScript($document, $opType);
Expand All @@ -225,7 +226,7 @@ public function addScripts(array $scripts, $opType = null)
*
* @return $this
*/
public function addData($data, $opType = null)
public function addData($data, string $opType = null)
{
if (!is_array($data)) {
$data = [$data];
Expand All @@ -247,11 +248,11 @@ public function addData($data, $opType = null)
/**
* @param array $data
*
* @throws \Elastica\Exception\InvalidException
* @throws InvalidException
*
* @return $this
*/
public function addRawData(array $data)
public function addRawData(array $data): self
{
foreach ($data as $row) {
if (is_array($row)) {
Expand Down Expand Up @@ -287,11 +288,11 @@ public function addRawData(array $data)
* Set a url parameter on the request bulk request.
*
* @param string $name name of the parameter
* @param string $value value of the parameter
* @param mixed $value value of the parameter
*
* @return $this
*/
public function setRequestParam($name, $value)
public function setRequestParam(string $name, $value): self
{
$this->_requestParams[$name] = $value;

Expand All @@ -306,23 +307,23 @@ public function setRequestParam($name, $value)
*
* @return $this
*/
public function setShardTimeout($time)
public function setShardTimeout(string $time): self
{
return $this->setRequestParam('timeout', $time);
}

/**
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->toString();
}

/**
* @return string
*/
public function toString()
public function toString(): string
{
$data = '';
foreach ($this->getActions() as $action) {
Expand All @@ -335,7 +336,7 @@ public function toString()
/**
* @return array
*/
public function toArray()
public function toArray(): array
{
$data = [];
foreach ($this->getActions() as $action) {
Expand All @@ -348,9 +349,9 @@ public function toArray()
}

/**
* @return \Elastica\Bulk\ResponseSet
* @return ResponseSet
*/
public function send()
public function send(): ResponseSet
{
$path = $this->getPath();
$data = $this->toString();
Expand All @@ -361,14 +362,14 @@ public function send()
}

/**
* @param \Elastica\Response $response
* @param Response $response
*
* @throws \Elastica\Exception\Bulk\ResponseException
* @throws \Elastica\Exception\InvalidException
* @throws ResponseException
* @throws InvalidException
*
* @return \Elastica\Bulk\ResponseSet
* @return ResponseSet
*/
protected function _processResponse(Response $response)
protected function _processResponse(Response $response): ResponseSet
{
$responseData = $response->getData();

Expand Down

0 comments on commit 8a432f7

Please sign in to comment.