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

Fix CS bis #1706

Merged
merged 6 commits into from
Nov 19, 2019
Merged
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
2 changes: 2 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ $config = PhpCsFixer\Config::create()
'@PHPUnit60Migration:risky' => true,
'php_unit_dedicate_assert' => ['target' => 'newest'],
'native_function_invocation' => true,
'no_alias_functions' => true,
thePanz marked this conversation as resolved.
Show resolved Hide resolved
'nullable_type_declaration_for_default_null_value' => true,
])
;

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file based on the
### Improvements

* Launch tests with PHP 7.4
* Added `nullable_type_declaration_for_default_null_value`, `no_alias_functions` CS rules [#1706](https://github.com/ruflin/Elastica/pull/1706)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/AbstractUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AbstractUpdateAction extends Param
/**
* Sets the id of the document.
*/
public function setId(string $id = null): self
public function setId(?string $id = null): self
{
return $this->setParam('_id', $id);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Aggregation/AbstractAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function toArray(): array
// compensate for class name GlobalAggregation
$array = ['global' => new \stdClass()];
}
if (\sizeof($this->_aggs)) {
if (\count($this->_aggs)) {
$array['aggs'] = $this->_convertArrayable($this->_aggs);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Aggregation/AbstractTermsAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function setMinimumDocumentCount(int $count): self
*
* @return $this
*/
public function setInclude(string $pattern, string $flags = null): self
public function setInclude(string $pattern, ?string $flags = null): self
{
if (null === $flags) {
return $this->setParam('include', $pattern);
Expand All @@ -45,7 +45,7 @@ public function setInclude(string $pattern, string $flags = null): self
*
* @return $this
*/
public function setExclude(string $pattern, string $flags = null): self
public function setExclude(string $pattern, ?string $flags = null): self
{
if (null === $flags) {
return $this->setParam('exclude', $pattern);
Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Aggregation/AvgBucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AvgBucket extends AbstractAggregation
const DEFAULT_GAP_POLICY_VALUE = 'skip';
const DEFAULT_FORMAT_VALUE = null;

public function __construct(string $name, string $bucketsPath = null)
public function __construct(string $name, ?string $bucketsPath = null)
{
parent::__construct($name);

Expand Down Expand Up @@ -48,7 +48,7 @@ public function setGapPolicy(string $gapPolicy): self
*
* @return $this
*/
public function setFormat(string $format = null): self
public function setFormat(?string $format = null): self
{
return $this->setParam('format', $format);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Aggregation/BucketScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class BucketScript extends AbstractAggregation
{
public function __construct(string $name, array $bucketsPath = null, string $script = null)
public function __construct(string $name, ?array $bucketsPath = null, ?string $script = null)
{
parent::__construct($name);

Expand Down Expand Up @@ -59,7 +59,7 @@ public function setGapPolicy(string $gapPolicy = 'skip'): self
*
* @return $this
*/
public function setFormat(string $format = null): self
public function setFormat(?string $format = null): self
{
return $this->setParam('format', $format);
}
Expand Down
8 changes: 3 additions & 5 deletions lib/Elastica/Aggregation/BucketSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class BucketSelector extends AbstractSimpleAggregation
{
public function __construct(string $name, array $bucketsPath = null, string $script = null)
public function __construct(string $name, ?array $bucketsPath = null, ?string $script = null)
{
parent::__construct($name);

Expand All @@ -25,11 +25,9 @@ public function __construct(string $name, array $bucketsPath = null, string $scr
/**
* Set the buckets_path for this aggregation.
*
* @param array $bucketsPath
*
* @return $this
*/
public function setBucketsPath($bucketsPath)
public function setBucketsPath(array $bucketsPath): self
{
return $this->setParam('buckets_path', $bucketsPath);
}
Expand All @@ -39,7 +37,7 @@ public function setBucketsPath($bucketsPath)
*
* @return $this
*/
public function setGapPolicy(string $gapPolicy = 'skip')
public function setGapPolicy(string $gapPolicy = 'skip'): self
{
return $this->setParam('gap_policy', $gapPolicy);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Elastica/Aggregation/Derivative.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class Derivative extends AbstractAggregation
{
public function __construct(string $name, string $bucketsPath = null)
public function __construct(string $name, ?string $bucketsPath = null)
{
parent::__construct($name);

Expand All @@ -25,7 +25,7 @@ public function __construct(string $name, string $bucketsPath = null)
*
* @return $this
*/
public function setBucketsPath(string $bucketsPath)
public function setBucketsPath(string $bucketsPath): self
{
return $this->setParam('buckets_path', $bucketsPath);
}
Expand All @@ -35,7 +35,7 @@ public function setBucketsPath(string $bucketsPath)
*
* @return $this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return $this should be removed too :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets separate PR's which are fully automated and manual changes ;-)

*/
public function setGapPolicy(string $gapPolicy = 'skip')
public function setGapPolicy(string $gapPolicy = 'skip'): self
{
return $this->setParam('gap_policy', $gapPolicy);
}
Expand All @@ -45,7 +45,7 @@ public function setGapPolicy(string $gapPolicy = 'skip')
*
* @return $this
*/
public function setFormat(string $format)
public function setFormat(string $format): self
{
return $this->setParam('format', $format);
}
Expand Down
7 changes: 2 additions & 5 deletions lib/Elastica/Aggregation/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
*/
class Filter extends AbstractAggregation
{
/**
* @param AbstractQuery $filter
*/
public function __construct(string $name, AbstractQuery $filter = null)
public function __construct(string $name, ?AbstractQuery $filter = null)
{
parent::__construct($name);

Expand All @@ -29,7 +26,7 @@ public function __construct(string $name, AbstractQuery $filter = null)
*
* @return $this
*/
public function setFilter(AbstractQuery $filter)
public function setFilter(AbstractQuery $filter): self
{
return $this->setParam('filter', $filter);
}
Expand Down
4 changes: 1 addition & 3 deletions lib/Elastica/Aggregation/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ class Filters extends AbstractAggregation
*
* If a name is given, it will be added as a key, otherwise considered as an anonymous filter
*
* @param string $name
*
* @return $this
*/
public function addFilter(AbstractQuery $filter, string $name = null): self
public function addFilter(AbstractQuery $filter, ?string $name = null): self
{
$filterArray = [];

Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Aggregation/GeoDistance.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function setOrigin($origin): self
*
* @return $this
*/
public function addRange(int $fromValue = null, int $toValue = null): self
public function addRange(?int $fromValue = null, ?int $toValue = null): self
{
if (null === $fromValue && null === $toValue) {
throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.');
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Aggregation/IpRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function setField(string $field): self
*
* @return $this
*/
public function addRange(string $fromValue = null, string $toValue = null): self
public function addRange(?string $fromValue = null, ?string $toValue = null): self
{
if (null === $fromValue && null === $toValue) {
throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.');
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Aggregation/Percentiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Percentiles extends AbstractSimpleAggregation
* @param string $name the name of this aggregation
* @param string $field the field on which to perform this aggregation
*/
public function __construct(string $name, string $field = null)
public function __construct(string $name, ?string $field = null)
{
parent::__construct($name);

Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Aggregation/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Range extends AbstractSimpleAggregation
*
* @return $this
*/
public function addRange($fromValue = null, $toValue = null, string $key = null)
public function addRange($fromValue = null, $toValue = null, ?string $key = null): self
{
if (null === $fromValue && null === $toValue) {
throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.');
Expand Down Expand Up @@ -50,7 +50,7 @@ public function addRange($fromValue = null, $toValue = null, string $key = null)
*
* @return $this
*/
public function setKeyedResponse(bool $keyed = true)
public function setKeyedResponse(bool $keyed = true): self
{
return $this->setParam('keyed', $keyed);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Aggregation/ReverseNested.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ReverseNested extends AbstractAggregation
* @param string $name The name of this aggregation
* @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document.
*/
public function __construct(string $name, string $path = null)
public function __construct(string $name, ?string $path = null)
{
parent::__construct($name);

Expand All @@ -27,7 +27,7 @@ public function __construct(string $name, string $path = null)
*
* @return $this
*/
public function setPath(string $path)
public function setPath(string $path): self
{
return $this->setParam('path', $path);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Elastica/Aggregation/ScriptedMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class ScriptedMetric extends AbstractAggregation
*/
public function __construct(
string $name,
string $initScript = null,
string $mapScript = null,
string $combineScript = null,
string $reduceScript = null
?string $initScript = null,
?string $mapScript = null,
?string $combineScript = null,
?string $reduceScript = null
) {
parent::__construct($name);
if ($initScript) {
Expand Down
6 changes: 2 additions & 4 deletions lib/Elastica/Aggregation/SerialDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SerialDiff extends AbstractAggregation
{
const DEFAULT_GAP_POLICY_VALUE = 'insert_zero';

public function __construct(string $name, string $bucketsPath = null)
public function __construct(string $name, ?string $bucketsPath = null)
{
parent::__construct($name);

Expand Down Expand Up @@ -55,11 +55,9 @@ public function setGapPolicy(string $gapPolicy): self
/**
* Set the format for this aggregation.
*
* @param string $format
*
* @return $this
*/
public function setFormat(string $format = null): self
public function setFormat(?string $format = null): self
{
return $this->setParam('format', $format);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Aggregation/StatsBucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class StatsBucket extends AbstractAggregation
{
public function __construct(string $name, string $bucketsPath = null)
public function __construct(string $name, ?string $bucketsPath = null)
{
parent::__construct($name);

Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Aggregation/SumBucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class SumBucket extends AbstractAggregation
{
public function __construct(string $name, string $bucketsPath = null)
public function __construct(string $name, ?string $bucketsPath = null)
{
parent::__construct($name);

Expand Down
15 changes: 4 additions & 11 deletions lib/Elastica/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,9 @@ public function getActions(): array
}

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

Expand All @@ -131,11 +129,10 @@ public function addDocument(Document $document, string $opType = null): self

/**
* @param Document[] $documents
* @param string $opType
*
* @return $this
*/
public function addDocuments(array $documents, string $opType = null): self
public function addDocuments(array $documents, ?string $opType = null): self
{
foreach ($documents as $document) {
$this->addDocument($document, $opType);
Expand All @@ -145,11 +142,9 @@ public function addDocuments(array $documents, string $opType = null): self
}

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

Expand All @@ -158,7 +153,6 @@ public function addScript(AbstractScript $script, string $opType = null): self

/**
* @param Document[] $scripts
* @param string $opType
*
* @return $this
*/
Expand All @@ -173,11 +167,10 @@ public function addScripts(array $scripts, $opType = null): self

/**
* @param \Elastica\Script\AbstractScript|\Elastica\Document|array $data
* @param string $opType
*
* @return $this
*/
public function addData($data, string $opType = null)
public function addData($data, ?string $opType = null)
{
if (!\is_array($data)) {
$data = [$data];
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Bulk/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function toString(): string
return $string;
}

public static function isValidOpType(string $opType = null): bool
public static function isValidOpType(?string $opType = null): bool
{
return \in_array($opType, self::$opTypes, true);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Bulk/Action/AbstractDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ abstract protected function _getMetadata(AbstractUpdateAction $source): array;
*
* @return static
*/
public static function create($data, string $opType = null): self
public static function create($data, ?string $opType = null): self
{
//Check type
if (!$data instanceof Document && !$data instanceof AbstractScript) {
Expand Down
Loading