Skip to content

Commit

Permalink
[6.x] No php 8.1 deprecation warnings (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Apr 13, 2022
1 parent 43dc1cd commit f0f5487
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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'
Expand Down
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])
;

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 @@ 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)
Expand Down
4 changes: 1 addition & 3 deletions lib/Elastica/Aggregation/AbstractSimpleAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion lib/Elastica/ArrayableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/**
* Interface for params.
*
*
* @author Evgeniy Sokolov <ewgraf@gmail.com>
*/
interface ArrayableInterface
Expand Down
6 changes: 6 additions & 0 deletions lib/Elastica/Bulk/ResponseSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -114,6 +116,7 @@ public function next()
/**
* @return int
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this->_position;
Expand All @@ -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;
Expand All @@ -135,6 +140,7 @@ public function rewind()
/**
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->_bulkResponses);
Expand Down
10 changes: 10 additions & 0 deletions lib/Elastica/Multi/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -95,6 +97,7 @@ public function next()
/**
* @return int
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this->_position;
Expand All @@ -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;
Expand All @@ -116,6 +121,7 @@ public function rewind()
/**
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->_resultSets);
Expand All @@ -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]);
Expand All @@ -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;
Expand All @@ -145,6 +153,7 @@ public function offsetGet($offset)
* @param mixed $offset
* @param mixed $value
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
Expand All @@ -157,6 +166,7 @@ public function offsetSet($offset, $value)
/**
* @param mixed $offset
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->_resultSets[$offset]);
Expand Down
1 change: 0 additions & 1 deletion lib/Elastica/NameableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/**
* Interface for named objects.
*
*
* @author Evgeniy Sokolov <ewgraf@gmail.com>
*/
interface NameableInterface
Expand Down
1 change: 1 addition & 0 deletions lib/Elastica/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function getParams()
*
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->_params);
Expand Down
4 changes: 1 addition & 3 deletions lib/Elastica/Query/SpanNear.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions lib/Elastica/Query/SpanOr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions lib/Elastica/QueryBuilder/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions lib/Elastica/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public function getQuery()
*
* @return int Size of set
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->_results);
Expand All @@ -239,6 +240,7 @@ public function countSuggests()
*
* @return \Elastica\Result Set object
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->_results[$this->key()];
Expand All @@ -247,6 +249,7 @@ public function current()
/**
* Sets pointer (current) to the next item of the set.
*/
#[\ReturnTypeWillChange]
public function next()
{
++$this->_position;
Expand All @@ -257,6 +260,7 @@ public function next()
*
* @return int Current position
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this->_position;
Expand All @@ -267,6 +271,7 @@ public function key()
*
* @return bool True if object exists
*/
#[\ReturnTypeWillChange]
public function valid()
{
return isset($this->_results[$this->key()]);
Expand All @@ -275,6 +280,7 @@ public function valid()
/**
* Resets position to 0, restarts iterator.
*/
#[\ReturnTypeWillChange]
public function rewind()
{
$this->_position = 0;
Expand All @@ -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]);
Expand All @@ -305,6 +312,7 @@ public function offsetExists($offset)
*
* @return Result
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
if ($this->offsetExists($offset)) {
Expand All @@ -324,6 +332,7 @@ public function offsetGet($offset)
*
* @throws Exception\InvalidException
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (!($value instanceof Result)) {
Expand All @@ -344,6 +353,7 @@ public function offsetSet($offset, $value)
*
* @param int $offset
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->_results[$offset]);
Expand Down
5 changes: 5 additions & 0 deletions lib/Elastica/Scroll.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function __construct(Search $search, $expiryTime = '1m')
*
* @return ResultSet
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->_currentResultSet;
Expand All @@ -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) {
Expand All @@ -95,6 +97,7 @@ public function next()
*
* @return string
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this->_nextScrollId;
Expand All @@ -107,6 +110,7 @@ public function key()
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function valid()
{
return null !== $this->_nextScrollId;
Expand All @@ -117,6 +121,7 @@ public function valid()
*
* @see http://php.net/manual/en/iterator.rewind.php
*/
#[\ReturnTypeWillChange]
public function rewind()
{
// reset state
Expand Down
1 change: 0 additions & 1 deletion test/Elastica/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f0f5487

Please sign in to comment.