Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing types #2112

Open
wants to merge 1 commit into
base: 8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'ordered_imports' => true,
'php_unit_dedicate_assert' => ['target' => 'newest'],
'php_unit_test_class_requires_covers' => false,
'phpdoc_no_empty_return' => false,
'phpdoc_order' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last'],
'static_lambda' => true,
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/ruflin/Elastica/compare/7.2.0...master)
### Backward Compatibility Breaks
### Added
* Added missing type declarations [#2112](https://github.com/ruflin/Elastica/pull/2112)
### Changed
### Deprecated
### Removed
Expand Down
3 changes: 3 additions & 0 deletions src/Bulk/ResponseSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Elastica\Response as BaseResponse;

/**
* @template-implements \Iterator<int, Response>
*/
class ResponseSet extends BaseResponse implements \Iterator, \Countable
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ public function getCluster()

/**
* Establishes the client connections.
*
* @return void
*/
public function connect()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Index/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public function getData(): array
* Returns the entry in the data array based on the params.
* Various params possible.
*
* @param mixed $args
*
* @return mixed Data array entry or null if not found
*/
public function get(...$args)
Expand Down
3 changes: 3 additions & 0 deletions src/Multi/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
* List of result sets for each search request.
*
* @author munkie
*
* @template-implements \Iterator<int, BaseResultSet>
* @template-implements \ArrayAccess<int|string, BaseResultSet>
*/
class ResultSet implements \Iterator, \ArrayAccess, \Countable
{
Expand Down
3 changes: 2 additions & 1 deletion src/Multi/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class Search
* @var BaseSearch[]
*/
protected $_searches = [];

/**
* @const string[] valid header options
* @var string[] valid header options
*/
private static $HEADER_OPTIONS = [
'index',
Expand Down
2 changes: 2 additions & 0 deletions src/Node/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function __construct(BaseNode $node, array $params = [])
* node is running on
* Example 2: get('os', 'mem') returns an array with all mem infos
*
* @param mixed $args
*
* @return mixed Data array entry or null if not found
*/
public function get(...$args)
Expand Down
2 changes: 2 additions & 0 deletions src/Node/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function __construct(BaseNode $node)
* Several arguments can be use
* get('index', 'test', 'example')
*
* @param mixed $args
*
* @return array|null Node stats for the given field or null if not found
*/
public function get(...$args)
Expand Down
2 changes: 2 additions & 0 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Query extends Param
{
/**
* If the current query has a suggest in it.
*
* @var bool
*/
private $hasSuggest = false;

Expand Down
5 changes: 4 additions & 1 deletion src/Query/DistanceFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
class DistanceFeature extends AbstractQuery
{
/**
* @param array{float, float}|string $origin
*/
public function __construct(string $field, $origin, string $pivot)
{
$this->setField($field);
Expand All @@ -22,7 +25,7 @@ public function setField(string $field): self
}

/**
* @param array|string $origin
* @param array{float, float}|string $origin
*/
public function setOrigin($origin): self
{
Expand Down
3 changes: 3 additions & 0 deletions src/Query/FunctionScore.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class FunctionScore extends AbstractQuery
public const RANDOM_SCORE_FIELD_ID = '_id';
public const RANDOM_SCORE_FIELD_SEQ_NO = '_seq_no';

/**
* @var array<string, mixed>
*/
protected $_functions = [];

/**
Expand Down
15 changes: 15 additions & 0 deletions src/Reindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,33 @@ public function setWaitForCompletion($value): void
$this->setParam(self::WAIT_FOR_COMPLETION, $value);
}

/**
* @param string $value
*/
public function setWaitForActiveShards($value): void
{
$this->setParam(self::WAIT_FOR_ACTIVE_SHARDS, $value);
}

/**
* @param string $value
*/
public function setTimeout($value): void
{
$this->setParam(self::TIMEOUT, $value);
}

/**
* @param string $value
*/
public function setScroll($value): void
{
$this->setParam(self::SCROLL, $value);
}

/**
* @param int $value
*/
public function setRequestsPerSecond($value): void
{
$this->setParam(self::REQUESTS_PER_SECOND, $value);
Expand All @@ -131,6 +143,9 @@ public function setRefresh(string $value): void
$this->setParam(self::REFRESH, $value);
}

/**
* @return string|null
*/
public function getTaskId()
{
$taskId = null;
Expand Down
2 changes: 2 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public function getConnection(): Connection

/**
* Set the Content-Type of this request.
*
* @return $this
*/
public function setContentType(string $contentType)
{
Expand Down
3 changes: 3 additions & 0 deletions src/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* Result set implements iterator
*
* @author Nicolas Ruflin <[email protected]>
*
* @template-implements \Iterator<int, Result>
* @template-implements \ArrayAccess<int, Result>
*/
class ResultSet implements \Iterator, \Countable, \ArrayAccess
{
Expand Down
2 changes: 2 additions & 0 deletions src/ResultSet/ProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface ProcessorInterface
/**
* Iterates over a ResultSet allowing a processor to iterate over any
* Results as required.
*
* @return void
*/
public function process(ResultSet $resultSet);
}
7 changes: 6 additions & 1 deletion src/Script/AbstractScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(?array $params = null, ?string $lang = null, ?string
/**
* Factory to create a script object from data structure (reverse toArray).
*
* @param AbstractScript|array|string $data
* @param AbstractScript|array{script: array<string, mixed>}|string $data
*
* @throws InvalidException
*
Expand Down Expand Up @@ -114,6 +114,11 @@ public function toArray(): array
*/
abstract protected function getScriptTypeArray(): array;

/**
* @param array{script: array<string, mixed>} $data
*
* @return Script|ScriptId
*/
private static function _createFromArray(array $data)
{
$params = $data['script']['params'] ?? [];
Expand Down
11 changes: 10 additions & 1 deletion src/Scroll.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* @author Manuel Andreo Garcia <[email protected]>
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
*
* @template-implements \Iterator<string|null, ResultSet>
*/
class Scroll implements \Iterator
{
Expand Down Expand Up @@ -38,11 +40,18 @@ class Scroll implements \Iterator
* 1: scroll id.
* 2: ignore_unavailable.
*
* @var array
* @var array{mixed, mixed, mixed}
*/
protected $_options = [null, null, null];

/**
* @var int
*/
private $totalPages = 0;

/**
* @var int
*/
private $currentPage = 0;

public function __construct(Search $search, string $expiryTime = '1m')
Expand Down
6 changes: 3 additions & 3 deletions tests/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,22 @@ protected function _createRenamePipeline(): void
$client->requestEndpoint($endpoint);
}

protected function _checkPlugin($plugin): void
protected function _checkPlugin(string $plugin): void
{
$nodes = $this->_getClient()->getCluster()->getNodes();
if (!$nodes[0]->getInfo()->hasPlugin($plugin)) {
$this->markTestSkipped($plugin.' plugin not installed.');
}
}

protected function _getVersion()
protected function _getVersion(): string
{
$data = $this->_getClient()->request('/')->getData();

return \substr($data['version']['number'], 0, 1);
}

protected function _checkVersion($version): void
protected function _checkVersion(string $version): void
{
$data = $this->_getClient()->request('/')->getData();
$installedVersion = $data['version']['number'];
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/AbstractExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testInheritance(): void
$this->assertTrue($reflection->implementsInterface(ExceptionInterface::class));
}

protected function _getExceptionClass()
protected function _getExceptionClass(): string
{
$reflection = new \ReflectionObject($this);

Expand Down
3 changes: 3 additions & 0 deletions tests/Query/FunctionScoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
class FunctionScoreTest extends BaseTest
{
/**
* @var string
*/
protected $locationOrigin = '32.804654, -117.242594';

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Query/MultiMatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
*/
class MultiMatchTest extends BaseTest
{
/**
* @var array<array{
* id: int,
* name: string,
* last_name: string,
* full_name: string,
* }>
*/
private static $data = [
['id' => 1, 'name' => 'Rodolfo', 'last_name' => 'Moraes', 'full_name' => 'Rodolfo Moraes'],
['id' => 2, 'name' => 'Tristan', 'last_name' => 'Maindron', 'full_name' => 'Tristan Maindron'],
Expand Down
22 changes: 22 additions & 0 deletions tests/Transport/TransportBenchmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,24 @@
*/
class TransportBenchmarkTest extends BaseTest
{
/**
* @var int
*/
protected $_max = 1000;

/**
* @var int
*/
protected $_maxData = 20;

/**
* @var array<string, array<string, array{
thePanz marked this conversation as resolved.
Show resolved Hide resolved
* count: int,
* max: int,
* min: int,
* mean: float,
* }>>
thePanz marked this conversation as resolved.
Show resolved Hide resolved
*/
protected static $_results = [];

public static function tearDownAfterClass(): void
Expand Down Expand Up @@ -176,6 +192,12 @@ protected function getIndex(array $config): Index
return $index;
}

/**
* @return array{
* test: string,
* name: string[],
* }
*/
protected function getData(string $test): array
{
$data = [
Expand Down