Skip to content

Commit 0d32a39

Browse files
deguifruflin
authored andcommitted
Fix CS bis (#1706)
1 parent 1909c67 commit 0d32a39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+186
-327
lines changed

.php_cs.dist

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ $config = PhpCsFixer\Config::create()
1919
'@PHPUnit60Migration:risky' => true,
2020
'php_unit_dedicate_assert' => ['target' => 'newest'],
2121
'native_function_invocation' => true,
22+
'no_alias_functions' => true,
23+
'nullable_type_declaration_for_default_null_value' => true,
2224
])
2325
;
2426

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file based on the
2222
### Improvements
2323

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

2627
### Deprecated
2728

lib/Elastica/AbstractUpdateAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AbstractUpdateAction extends Param
1818
/**
1919
* Sets the id of the document.
2020
*/
21-
public function setId(string $id = null): self
21+
public function setId(?string $id = null): self
2222
{
2323
return $this->setParam('_id', $id);
2424
}

lib/Elastica/Aggregation/AbstractAggregation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function toArray(): array
132132
// compensate for class name GlobalAggregation
133133
$array = ['global' => new \stdClass()];
134134
}
135-
if (\sizeof($this->_aggs)) {
135+
if (\count($this->_aggs)) {
136136
$array['aggs'] = $this->_convertArrayable($this->_aggs);
137137
}
138138

lib/Elastica/Aggregation/AbstractTermsAggregation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function setMinimumDocumentCount(int $count): self
2525
*
2626
* @return $this
2727
*/
28-
public function setInclude(string $pattern, string $flags = null): self
28+
public function setInclude(string $pattern, ?string $flags = null): self
2929
{
3030
if (null === $flags) {
3131
return $this->setParam('include', $pattern);
@@ -45,7 +45,7 @@ public function setInclude(string $pattern, string $flags = null): self
4545
*
4646
* @return $this
4747
*/
48-
public function setExclude(string $pattern, string $flags = null): self
48+
public function setExclude(string $pattern, ?string $flags = null): self
4949
{
5050
if (null === $flags) {
5151
return $this->setParam('exclude', $pattern);

lib/Elastica/Aggregation/AvgBucket.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AvgBucket extends AbstractAggregation
1414
const DEFAULT_GAP_POLICY_VALUE = 'skip';
1515
const DEFAULT_FORMAT_VALUE = null;
1616

17-
public function __construct(string $name, string $bucketsPath = null)
17+
public function __construct(string $name, ?string $bucketsPath = null)
1818
{
1919
parent::__construct($name);
2020

@@ -48,7 +48,7 @@ public function setGapPolicy(string $gapPolicy): self
4848
*
4949
* @return $this
5050
*/
51-
public function setFormat(string $format = null): self
51+
public function setFormat(?string $format = null): self
5252
{
5353
return $this->setParam('format', $format);
5454
}

lib/Elastica/Aggregation/BucketScript.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
class BucketScript extends AbstractAggregation
1313
{
14-
public function __construct(string $name, array $bucketsPath = null, string $script = null)
14+
public function __construct(string $name, ?array $bucketsPath = null, ?string $script = null)
1515
{
1616
parent::__construct($name);
1717

@@ -59,7 +59,7 @@ public function setGapPolicy(string $gapPolicy = 'skip'): self
5959
*
6060
* @return $this
6161
*/
62-
public function setFormat(string $format = null): self
62+
public function setFormat(?string $format = null): self
6363
{
6464
return $this->setParam('format', $format);
6565
}

lib/Elastica/Aggregation/BucketSelector.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class BucketSelector extends AbstractSimpleAggregation
1111
{
12-
public function __construct(string $name, array $bucketsPath = null, string $script = null)
12+
public function __construct(string $name, ?array $bucketsPath = null, ?string $script = null)
1313
{
1414
parent::__construct($name);
1515

@@ -25,11 +25,9 @@ public function __construct(string $name, array $bucketsPath = null, string $scr
2525
/**
2626
* Set the buckets_path for this aggregation.
2727
*
28-
* @param array $bucketsPath
29-
*
3028
* @return $this
3129
*/
32-
public function setBucketsPath($bucketsPath)
30+
public function setBucketsPath(array $bucketsPath): self
3331
{
3432
return $this->setParam('buckets_path', $bucketsPath);
3533
}
@@ -39,7 +37,7 @@ public function setBucketsPath($bucketsPath)
3937
*
4038
* @return $this
4139
*/
42-
public function setGapPolicy(string $gapPolicy = 'skip')
40+
public function setGapPolicy(string $gapPolicy = 'skip'): self
4341
{
4442
return $this->setParam('gap_policy', $gapPolicy);
4543
}

lib/Elastica/Aggregation/Derivative.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
class Derivative extends AbstractAggregation
1313
{
14-
public function __construct(string $name, string $bucketsPath = null)
14+
public function __construct(string $name, ?string $bucketsPath = null)
1515
{
1616
parent::__construct($name);
1717

@@ -25,7 +25,7 @@ public function __construct(string $name, string $bucketsPath = null)
2525
*
2626
* @return $this
2727
*/
28-
public function setBucketsPath(string $bucketsPath)
28+
public function setBucketsPath(string $bucketsPath): self
2929
{
3030
return $this->setParam('buckets_path', $bucketsPath);
3131
}
@@ -35,7 +35,7 @@ public function setBucketsPath(string $bucketsPath)
3535
*
3636
* @return $this
3737
*/
38-
public function setGapPolicy(string $gapPolicy = 'skip')
38+
public function setGapPolicy(string $gapPolicy = 'skip'): self
3939
{
4040
return $this->setParam('gap_policy', $gapPolicy);
4141
}
@@ -45,7 +45,7 @@ public function setGapPolicy(string $gapPolicy = 'skip')
4545
*
4646
* @return $this
4747
*/
48-
public function setFormat(string $format)
48+
public function setFormat(string $format): self
4949
{
5050
return $this->setParam('format', $format);
5151
}

lib/Elastica/Aggregation/Filter.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
*/
1313
class Filter extends AbstractAggregation
1414
{
15-
/**
16-
* @param AbstractQuery $filter
17-
*/
18-
public function __construct(string $name, AbstractQuery $filter = null)
15+
public function __construct(string $name, ?AbstractQuery $filter = null)
1916
{
2017
parent::__construct($name);
2118

@@ -29,7 +26,7 @@ public function __construct(string $name, AbstractQuery $filter = null)
2926
*
3027
* @return $this
3128
*/
32-
public function setFilter(AbstractQuery $filter)
29+
public function setFilter(AbstractQuery $filter): self
3330
{
3431
return $this->setParam('filter', $filter);
3532
}

lib/Elastica/Aggregation/Filters.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ class Filters extends AbstractAggregation
2525
*
2626
* If a name is given, it will be added as a key, otherwise considered as an anonymous filter
2727
*
28-
* @param string $name
29-
*
3028
* @return $this
3129
*/
32-
public function addFilter(AbstractQuery $filter, string $name = null): self
30+
public function addFilter(AbstractQuery $filter, ?string $name = null): self
3331
{
3432
$filterArray = [];
3533

lib/Elastica/Aggregation/GeoDistance.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function setOrigin($origin): self
6262
*
6363
* @return $this
6464
*/
65-
public function addRange(int $fromValue = null, int $toValue = null): self
65+
public function addRange(?int $fromValue = null, ?int $toValue = null): self
6666
{
6767
if (null === $fromValue && null === $toValue) {
6868
throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.');

lib/Elastica/Aggregation/IpRange.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function setField(string $field): self
4343
*
4444
* @return $this
4545
*/
46-
public function addRange(string $fromValue = null, string $toValue = null): self
46+
public function addRange(?string $fromValue = null, ?string $toValue = null): self
4747
{
4848
if (null === $fromValue && null === $toValue) {
4949
throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.');

lib/Elastica/Aggregation/Percentiles.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Percentiles extends AbstractSimpleAggregation
1313
* @param string $name the name of this aggregation
1414
* @param string $field the field on which to perform this aggregation
1515
*/
16-
public function __construct(string $name, string $field = null)
16+
public function __construct(string $name, ?string $field = null)
1717
{
1818
parent::__construct($name);
1919

lib/Elastica/Aggregation/Range.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Range extends AbstractSimpleAggregation
2222
*
2323
* @return $this
2424
*/
25-
public function addRange($fromValue = null, $toValue = null, string $key = null)
25+
public function addRange($fromValue = null, $toValue = null, ?string $key = null): self
2626
{
2727
if (null === $fromValue && null === $toValue) {
2828
throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.');
@@ -50,7 +50,7 @@ public function addRange($fromValue = null, $toValue = null, string $key = null)
5050
*
5151
* @return $this
5252
*/
53-
public function setKeyedResponse(bool $keyed = true)
53+
public function setKeyedResponse(bool $keyed = true): self
5454
{
5555
return $this->setParam('keyed', $keyed);
5656
}

lib/Elastica/Aggregation/ReverseNested.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ReverseNested extends AbstractAggregation
1313
* @param string $name The name of this aggregation
1414
* @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document.
1515
*/
16-
public function __construct(string $name, string $path = null)
16+
public function __construct(string $name, ?string $path = null)
1717
{
1818
parent::__construct($name);
1919

@@ -27,7 +27,7 @@ public function __construct(string $name, string $path = null)
2727
*
2828
* @return $this
2929
*/
30-
public function setPath(string $path)
30+
public function setPath(string $path): self
3131
{
3232
return $this->setParam('path', $path);
3333
}

lib/Elastica/Aggregation/ScriptedMetric.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class ScriptedMetric extends AbstractAggregation
1818
*/
1919
public function __construct(
2020
string $name,
21-
string $initScript = null,
22-
string $mapScript = null,
23-
string $combineScript = null,
24-
string $reduceScript = null
21+
?string $initScript = null,
22+
?string $mapScript = null,
23+
?string $combineScript = null,
24+
?string $reduceScript = null
2525
) {
2626
parent::__construct($name);
2727
if ($initScript) {

lib/Elastica/Aggregation/SerialDiff.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SerialDiff extends AbstractAggregation
1313
{
1414
const DEFAULT_GAP_POLICY_VALUE = 'insert_zero';
1515

16-
public function __construct(string $name, string $bucketsPath = null)
16+
public function __construct(string $name, ?string $bucketsPath = null)
1717
{
1818
parent::__construct($name);
1919

@@ -55,11 +55,9 @@ public function setGapPolicy(string $gapPolicy): self
5555
/**
5656
* Set the format for this aggregation.
5757
*
58-
* @param string $format
59-
*
6058
* @return $this
6159
*/
62-
public function setFormat(string $format = null): self
60+
public function setFormat(?string $format = null): self
6361
{
6462
return $this->setParam('format', $format);
6563
}

lib/Elastica/Aggregation/StatsBucket.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
class StatsBucket extends AbstractAggregation
1313
{
14-
public function __construct(string $name, string $bucketsPath = null)
14+
public function __construct(string $name, ?string $bucketsPath = null)
1515
{
1616
parent::__construct($name);
1717

lib/Elastica/Aggregation/SumBucket.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
class SumBucket extends AbstractAggregation
1313
{
14-
public function __construct(string $name, string $bucketsPath = null)
14+
public function __construct(string $name, ?string $bucketsPath = null)
1515
{
1616
parent::__construct($name);
1717

lib/Elastica/Bulk.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,9 @@ public function getActions(): array
118118
}
119119

120120
/**
121-
* @param string $opType
122-
*
123121
* @return $this
124122
*/
125-
public function addDocument(Document $document, string $opType = null): self
123+
public function addDocument(Document $document, ?string $opType = null): self
126124
{
127125
$action = AbstractDocumentAction::create($document, $opType);
128126

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

132130
/**
133131
* @param Document[] $documents
134-
* @param string $opType
135132
*
136133
* @return $this
137134
*/
138-
public function addDocuments(array $documents, string $opType = null): self
135+
public function addDocuments(array $documents, ?string $opType = null): self
139136
{
140137
foreach ($documents as $document) {
141138
$this->addDocument($document, $opType);
@@ -145,11 +142,9 @@ public function addDocuments(array $documents, string $opType = null): self
145142
}
146143

147144
/**
148-
* @param string $opType
149-
*
150145
* @return $this
151146
*/
152-
public function addScript(AbstractScript $script, string $opType = null): self
147+
public function addScript(AbstractScript $script, ?string $opType = null): self
153148
{
154149
$action = AbstractDocumentAction::create($script, $opType);
155150

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

159154
/**
160155
* @param Document[] $scripts
161-
* @param string $opType
162156
*
163157
* @return $this
164158
*/
@@ -173,11 +167,10 @@ public function addScripts(array $scripts, $opType = null): self
173167

174168
/**
175169
* @param \Elastica\Script\AbstractScript|\Elastica\Document|array $data
176-
* @param string $opType
177170
*
178171
* @return $this
179172
*/
180-
public function addData($data, string $opType = null)
173+
public function addData($data, ?string $opType = null)
181174
{
182175
if (!\is_array($data)) {
183176
$data = [$data];

lib/Elastica/Bulk/Action.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function toString(): string
175175
return $string;
176176
}
177177

178-
public static function isValidOpType(string $opType = null): bool
178+
public static function isValidOpType(?string $opType = null): bool
179179
{
180180
return \in_array($opType, self::$opTypes, true);
181181
}

lib/Elastica/Bulk/Action/AbstractDocument.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ abstract protected function _getMetadata(AbstractUpdateAction $source): array;
121121
*
122122
* @return static
123123
*/
124-
public static function create($data, string $opType = null): self
124+
public static function create($data, ?string $opType = null): self
125125
{
126126
//Check type
127127
if (!$data instanceof Document && !$data instanceof AbstractScript) {

0 commit comments

Comments
 (0)