diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 577b726307..cbd6cc3879 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -14,7 +14,7 @@ jobs: php-version: '7.0' coverage: 'none' extensions: 'json, mbstring, tokenizer' - tools: 'php-cs-fixer:2.14.0' + tools: 'php-cs-fixer:2.19.3' - name: 'Check PHP code' run: | @@ -39,6 +39,8 @@ jobs: elasticsearch: '6.5.2' - php: '8.0' elasticsearch: '6.5.2' + - php: '8.1' + elasticsearch: '6.5.2' fail-fast: false steps: - name: 'Checkout' diff --git a/.php_cs.dist b/.php_cs.dist index 19ff470165..72b69fb6ef 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -18,6 +18,7 @@ $config = PhpCsFixer\Config::create() 'no_useless_else' => true, '@PHPUnit60Migration:risky' => true, 'php_unit_dedicate_assert' => ['target' => 'newest'], + 'no_superfluous_phpdoc_tags' => false, ]) ; diff --git a/CHANGELOG.md b/CHANGELOG.md index d83f274fb8..b72aeeab5e 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file based on the ### Bugfixes ### Added ### Improvements +* Solve PHP 8.1 deprecations for every class implementing Countable, Iterator or ArrayAccess [#2061](https://github.com/ruflin/Elastica/pull/2061) ### Deprecated ## [6.2.0](https://github.com/ruflin/Elastica/compare/6.1.5...6.2.0) diff --git a/lib/Elastica/Aggregation/AbstractSimpleAggregation.php b/lib/Elastica/Aggregation/AbstractSimpleAggregation.php index 88210a0953..ba81bacbf6 100644 --- a/lib/Elastica/Aggregation/AbstractSimpleAggregation.php +++ b/lib/Elastica/Aggregation/AbstractSimpleAggregation.php @@ -36,9 +36,7 @@ public function setScript($script) public function toArray() { if (!$this->hasParam('field') && !$this->hasParam('script')) { - throw new InvalidException( - 'Either the field param or the script param should be set' - ); + throw new InvalidException('Either the field param or the script param should be set'); } $array = parent::toArray(); diff --git a/lib/Elastica/ArrayableInterface.php b/lib/Elastica/ArrayableInterface.php index 1f92e8a41a..5e6b4debf3 100644 --- a/lib/Elastica/ArrayableInterface.php +++ b/lib/Elastica/ArrayableInterface.php @@ -5,7 +5,6 @@ /** * Interface for params. * - * * @author Evgeniy Sokolov */ interface ArrayableInterface diff --git a/lib/Elastica/Bulk/ResponseSet.php b/lib/Elastica/Bulk/ResponseSet.php index 0bcb5e9d90..adf754c4d4 100644 --- a/lib/Elastica/Bulk/ResponseSet.php +++ b/lib/Elastica/Bulk/ResponseSet.php @@ -101,11 +101,13 @@ public function hasError() /** * @return \Elastica\Bulk\Response */ + #[\ReturnTypeWillChange] public function current() { return $this->_bulkResponses[$this->key()]; } + #[\ReturnTypeWillChange] public function next() { ++$this->_position; @@ -114,6 +116,7 @@ public function next() /** * @return int */ + #[\ReturnTypeWillChange] public function key() { return $this->_position; @@ -122,11 +125,13 @@ public function key() /** * @return bool */ + #[\ReturnTypeWillChange] public function valid() { return isset($this->_bulkResponses[$this->key()]); } + #[\ReturnTypeWillChange] public function rewind() { $this->_position = 0; @@ -135,6 +140,7 @@ public function rewind() /** * @return int */ + #[\ReturnTypeWillChange] public function count() { return count($this->_bulkResponses); diff --git a/lib/Elastica/Multi/ResultSet.php b/lib/Elastica/Multi/ResultSet.php index d611a324d3..3a4cb86051 100644 --- a/lib/Elastica/Multi/ResultSet.php +++ b/lib/Elastica/Multi/ResultSet.php @@ -82,11 +82,13 @@ public function hasError() /** * @return \Elastica\ResultSet */ + #[\ReturnTypeWillChange] public function current() { return $this->_resultSets[$this->key()]; } + #[\ReturnTypeWillChange] public function next() { ++$this->_position; @@ -95,6 +97,7 @@ public function next() /** * @return int */ + #[\ReturnTypeWillChange] public function key() { return $this->_position; @@ -103,11 +106,13 @@ public function key() /** * @return bool */ + #[\ReturnTypeWillChange] public function valid() { return isset($this->_resultSets[$this->key()]); } + #[\ReturnTypeWillChange] public function rewind() { $this->_position = 0; @@ -116,6 +121,7 @@ public function rewind() /** * @return int */ + #[\ReturnTypeWillChange] public function count() { return count($this->_resultSets); @@ -126,6 +132,7 @@ public function count() * * @return bool true on success or false on failure */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->_resultSets[$offset]); @@ -136,6 +143,7 @@ public function offsetExists($offset) * * @return mixed can return all value types */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->_resultSets[$offset] ?? null; @@ -145,6 +153,7 @@ public function offsetGet($offset) * @param mixed $offset * @param mixed $value */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { if (is_null($offset)) { @@ -157,6 +166,7 @@ public function offsetSet($offset, $value) /** * @param mixed $offset */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->_resultSets[$offset]); diff --git a/lib/Elastica/NameableInterface.php b/lib/Elastica/NameableInterface.php index 83b4373736..46e40062a0 100644 --- a/lib/Elastica/NameableInterface.php +++ b/lib/Elastica/NameableInterface.php @@ -5,7 +5,6 @@ /** * Interface for named objects. * - * * @author Evgeniy Sokolov */ interface NameableInterface diff --git a/lib/Elastica/Param.php b/lib/Elastica/Param.php index 0c765eb0b3..a49e155428 100644 --- a/lib/Elastica/Param.php +++ b/lib/Elastica/Param.php @@ -187,6 +187,7 @@ public function getParams() * * @return int */ + #[\ReturnTypeWillChange] public function count() { return count($this->_params); diff --git a/lib/Elastica/Query/SpanNear.php b/lib/Elastica/Query/SpanNear.php index aebc542f9f..5c662d9827 100644 --- a/lib/Elastica/Query/SpanNear.php +++ b/lib/Elastica/Query/SpanNear.php @@ -25,9 +25,7 @@ public function __construct($clauses = [], $slop = 1, $inOrder = false) if (!empty($clauses)) { foreach ($clauses as $clause) { if (!is_subclass_of($clause, AbstractSpanQuery::class)) { - throw new InvalidException( - 'Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery' - ); + throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery'); } } } diff --git a/lib/Elastica/Query/SpanOr.php b/lib/Elastica/Query/SpanOr.php index 67113c478a..f350d18771 100644 --- a/lib/Elastica/Query/SpanOr.php +++ b/lib/Elastica/Query/SpanOr.php @@ -23,9 +23,7 @@ public function __construct($clauses = []) if (!empty($clauses)) { foreach ($clauses as $clause) { if (!is_subclass_of($clause, AbstractSpanQuery::class)) { - throw new InvalidException( - 'Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery' - ); + throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery'); } } } diff --git a/lib/Elastica/QueryBuilder/Facade.php b/lib/Elastica/QueryBuilder/Facade.php index 3abe04efa6..2b6c05e862 100644 --- a/lib/Elastica/QueryBuilder/Facade.php +++ b/lib/Elastica/QueryBuilder/Facade.php @@ -47,17 +47,13 @@ public function __call($name, array $arguments) { // defined check if (false === method_exists($this->_dsl, $name)) { - throw new QueryBuilderException( - 'undefined '.$this->_dsl->getType().' "'.$name.'"' - ); + throw new QueryBuilderException('undefined '.$this->_dsl->getType().' "'.$name.'"'); } // version support check if (false === $this->_version->supports($name, $this->_dsl->getType())) { $reflection = new \ReflectionClass($this->_version); - throw new QueryBuilderException( - $this->_dsl->getType().' "'.$name.'" in '.$reflection->getShortName().' not supported' - ); + throw new QueryBuilderException($this->_dsl->getType().' "'.$name.'" in '.$reflection->getShortName().' not supported'); } return call_user_func_array([$this->_dsl, $name], $arguments); diff --git a/lib/Elastica/ResultSet.php b/lib/Elastica/ResultSet.php index e99d03ede8..c780e90d12 100644 --- a/lib/Elastica/ResultSet.php +++ b/lib/Elastica/ResultSet.php @@ -219,6 +219,7 @@ public function getQuery() * * @return int Size of set */ + #[\ReturnTypeWillChange] public function count() { return count($this->_results); @@ -239,6 +240,7 @@ public function countSuggests() * * @return \Elastica\Result Set object */ + #[\ReturnTypeWillChange] public function current() { return $this->_results[$this->key()]; @@ -247,6 +249,7 @@ public function current() /** * Sets pointer (current) to the next item of the set. */ + #[\ReturnTypeWillChange] public function next() { ++$this->_position; @@ -257,6 +260,7 @@ public function next() * * @return int Current position */ + #[\ReturnTypeWillChange] public function key() { return $this->_position; @@ -267,6 +271,7 @@ public function key() * * @return bool True if object exists */ + #[\ReturnTypeWillChange] public function valid() { return isset($this->_results[$this->key()]); @@ -275,6 +280,7 @@ public function valid() /** * Resets position to 0, restarts iterator. */ + #[\ReturnTypeWillChange] public function rewind() { $this->_position = 0; @@ -289,6 +295,7 @@ public function rewind() * * @return bool true on success or false on failure */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->_results[$offset]); @@ -305,6 +312,7 @@ public function offsetExists($offset) * * @return Result */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { if ($this->offsetExists($offset)) { @@ -324,6 +332,7 @@ public function offsetGet($offset) * * @throws Exception\InvalidException */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { if (!($value instanceof Result)) { @@ -344,6 +353,7 @@ public function offsetSet($offset, $value) * * @param int $offset */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->_results[$offset]); diff --git a/lib/Elastica/Scroll.php b/lib/Elastica/Scroll.php index 8a92fa31ee..04fcd29ee2 100644 --- a/lib/Elastica/Scroll.php +++ b/lib/Elastica/Scroll.php @@ -61,6 +61,7 @@ public function __construct(Search $search, $expiryTime = '1m') * * @return ResultSet */ + #[\ReturnTypeWillChange] public function current() { return $this->_currentResultSet; @@ -71,6 +72,7 @@ public function current() * * @see http://php.net/manual/en/iterator.next.php */ + #[\ReturnTypeWillChange] public function next() { if ($this->currentPage < $this->totalPages) { @@ -95,6 +97,7 @@ public function next() * * @return string */ + #[\ReturnTypeWillChange] public function key() { return $this->_nextScrollId; @@ -107,6 +110,7 @@ public function key() * * @return bool */ + #[\ReturnTypeWillChange] public function valid() { return null !== $this->_nextScrollId; @@ -117,6 +121,7 @@ public function valid() * * @see http://php.net/manual/en/iterator.rewind.php */ + #[\ReturnTypeWillChange] public function rewind() { // reset state diff --git a/test/Elastica/ClientTest.php b/test/Elastica/ClientTest.php index 9368bfd081..fb0fe8983f 100644 --- a/test/Elastica/ClientTest.php +++ b/test/Elastica/ClientTest.php @@ -17,7 +17,6 @@ use Elastica\Script\Script; use Elastica\Test\Base as BaseTest; use Elastica\Type; -use Elasticsearch\Endpoints\Get; use Elasticsearch\Endpoints\Indices\Stats; use Elasticsearch\Endpoints\Search; use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType;