Skip to content

Commit 9f81f52

Browse files
committed
Update phpstan to 2.x
1 parent 10e3232 commit 9f81f52

18 files changed

+127
-102
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
},
2323
"require-dev": {
2424
"guzzlehttp/guzzle": "^7.2",
25-
"phpstan/phpstan": "^1.5",
26-
"phpstan/phpstan-phpunit": "^1.1",
25+
"phpstan/phpstan": "^2.1",
26+
"phpstan/phpstan-phpunit": "^2.0",
2727
"phpunit/phpunit": "^10.5"
2828
},
2929
"conflict": {

phpstan-baseline.neon

Lines changed: 105 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,242 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Method Elastica\\\\QueryBuilder\\:\\:aggregation\\(\\) should return Elastica\\\\QueryBuilder\\\\DSL\\\\Aggregation but returns Elastica\\\\QueryBuilder\\\\Facade\\.$#"
4+
message: '#^Method Elastica\\QueryBuilder\:\:aggregation\(\) should return Elastica\\QueryBuilder\\DSL\\Aggregation but returns Elastica\\QueryBuilder\\Facade\.$#'
5+
identifier: return.type
56
count: 1
67
path: src/QueryBuilder.php
78

89
-
9-
message: "#^Method Elastica\\\\QueryBuilder\\:\\:collapse\\(\\) should return Elastica\\\\QueryBuilder\\\\DSL\\\\Collapse but returns Elastica\\\\QueryBuilder\\\\Facade\\.$#"
10+
message: '#^Method Elastica\\QueryBuilder\:\:collapse\(\) should return Elastica\\QueryBuilder\\DSL\\Collapse but returns Elastica\\QueryBuilder\\Facade\.$#'
11+
identifier: return.type
1012
count: 1
1113
path: src/QueryBuilder.php
1214

1315
-
14-
message: "#^Method Elastica\\\\QueryBuilder\\:\\:query\\(\\) should return Elastica\\\\QueryBuilder\\\\DSL\\\\Query but returns Elastica\\\\QueryBuilder\\\\Facade\\.$#"
16+
message: '#^Method Elastica\\QueryBuilder\:\:query\(\) should return Elastica\\QueryBuilder\\DSL\\Query but returns Elastica\\QueryBuilder\\Facade\.$#'
17+
identifier: return.type
1518
count: 1
1619
path: src/QueryBuilder.php
1720

1821
-
19-
message: "#^Method Elastica\\\\QueryBuilder\\:\\:suggest\\(\\) should return Elastica\\\\QueryBuilder\\\\DSL\\\\Suggest but returns Elastica\\\\QueryBuilder\\\\Facade\\.$#"
22+
message: '#^Method Elastica\\QueryBuilder\:\:suggest\(\) should return Elastica\\QueryBuilder\\DSL\\Suggest but returns Elastica\\QueryBuilder\\Facade\.$#'
23+
identifier: return.type
2024
count: 1
2125
path: src/QueryBuilder.php
2226

2327
-
24-
message: "#^Parameter \\#1 \\$precision of method Elastica\\\\Aggregation\\\\GeohashGrid\\:\\:setPrecision\\(\\) expects int\\|string, float given\\.$#"
28+
message: '#^Parameter \#1 \$precision of method Elastica\\Aggregation\\GeohashGrid\:\:setPrecision\(\) expects int\|string, float given\.$#'
29+
identifier: argument.type
2530
count: 1
2631
path: tests/Aggregation/GeohashGridTest.php
2732

2833
-
29-
message: "#^Parameter \\#1 \\$data of static method Elastica\\\\Bulk\\\\Action\\\\AbstractDocument\\:\\:create\\(\\) expects Elastica\\\\Document\\|Elastica\\\\Script\\\\AbstractScript, stdClass given\\.$#"
34+
message: '#^Parameter \#1 \$data of static method Elastica\\Bulk\\Action\\AbstractDocument\:\:create\(\) expects Elastica\\Document\|Elastica\\Script\\AbstractScript, stdClass given\.$#'
35+
identifier: argument.type
3036
count: 1
3137
path: tests/Bulk/Action/AbstractDocumentTest.php
3238

3339
-
34-
message: "#^Access to an undefined property Elastica\\\\Document\\:\\:\\$counter\\.$#"
40+
message: '#^Parameter \#1 \$expected of method PHPUnit\\Framework\\Assert\:\:assertSame\(\) contains unresolvable type\.$#'
41+
identifier: argument.unresolvableType
42+
count: 1
43+
path: tests/Bulk/Action/UpdateDocumentTest.php
44+
45+
-
46+
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Elastica\\\\Bulk\\\\Response'' and Elastica\\Bulk\\Response will always evaluate to true\.$#'
47+
identifier: method.alreadyNarrowedType
48+
count: 1
49+
path: tests/Bulk/ResponseSetTest.php
50+
51+
-
52+
message: '#^Access to an undefined property Elastica\\Document\:\:\$counter\.$#'
53+
identifier: property.notFound
3554
count: 1
3655
path: tests/BulkTest.php
3756

3857
-
39-
message: "#^Access to an undefined property Elastica\\\\Document\\:\\:\\$name\\.$#"
58+
message: '#^Access to an undefined property Elastica\\Document\:\:\$name\.$#'
59+
identifier: property.notFound
4060
count: 1
4161
path: tests/BulkTest.php
4262

4363
-
44-
message: "#^Access to an undefined property Elastica\\\\Document\\:\\:\\$test\\.$#"
64+
message: '#^Access to an undefined property Elastica\\Document\:\:\$test\.$#'
65+
identifier: property.notFound
4566
count: 3
4667
path: tests/BulkTest.php
4768

4869
-
49-
message: "#^Call to an undefined method Elastica\\\\Bulk\\\\Action\\:\\:getDocument\\(\\)\\.$#"
70+
message: '#^Call to an undefined method Elastica\\Bulk\\Action\:\:getDocument\(\)\.$#'
71+
identifier: method.notFound
5072
count: 3
5173
path: tests/BulkTest.php
5274

5375
-
54-
message: "#^Access to an undefined property Elastica\\\\Document\\:\\:\\$age\\.$#"
76+
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Elastica\\\\Bulk\\\\Response'' and Elastica\\Bulk\\Response will always evaluate to true\.$#'
77+
identifier: method.alreadyNarrowedType
78+
count: 1
79+
path: tests/BulkTest.php
80+
81+
-
82+
message: '#^Access to an undefined property Elastica\\Document\:\:\$age\.$#'
83+
identifier: property.notFound
5584
count: 1
5685
path: tests/ClientFunctionalTest.php
5786

5887
-
59-
message: "#^Parameter \\#2 \\$data of method Elastica\\\\Client\\:\\:updateDocument\\(\\) expects array\\|Elastica\\\\Document\\|Elastica\\\\Script\\\\AbstractScript, stdClass given\\.$#"
88+
message: '#^Parameter \#2 \$data of method Elastica\\Client\:\:updateDocument\(\) expects array\|Elastica\\Document\|Elastica\\Script\\AbstractScript, stdClass given\.$#'
89+
identifier: argument.type
6090
count: 1
6191
path: tests/ClientFunctionalTest.php
6292

6393
-
64-
message: "#^Access to an undefined property Elastica\\\\Document\\:\\:\\$field1\\.$#"
94+
message: '#^Access to an undefined property Elastica\\Document\:\:\$field1\.$#'
95+
identifier: property.notFound
6596
count: 1
6697
path: tests/DocumentTest.php
6798

6899
-
69-
message: "#^Access to an undefined property Elastica\\\\Document\\:\\:\\$field2\\.$#"
100+
message: '#^Access to an undefined property Elastica\\Document\:\:\$field2\.$#'
101+
identifier: property.notFound
70102
count: 1
71103
path: tests/DocumentTest.php
72104

73105
-
74-
message: "#^Access to an undefined property Elastica\\\\Document\\:\\:\\$field3\\.$#"
106+
message: '#^Access to an undefined property Elastica\\Document\:\:\$field3\.$#'
107+
identifier: property.notFound
75108
count: 1
76109
path: tests/DocumentTest.php
77110

78111
-
79-
message: "#^Access to an undefined property Elastica\\\\Document\\:\\:\\$field4\\.$#"
112+
message: '#^Access to an undefined property Elastica\\Document\:\:\$field4\.$#'
113+
identifier: property.notFound
80114
count: 1
81115
path: tests/DocumentTest.php
82116

83117
-
84-
message: "#^Access to an undefined property Elastica\\\\Document\\:\\:\\$field5\\.$#"
118+
message: '#^Access to an undefined property Elastica\\Document\:\:\$field5\.$#'
119+
identifier: property.notFound
85120
count: 1
86121
path: tests/DocumentTest.php
87122

88123
-
89-
message: "#^Dead catch \\- Elastica\\\\Exception\\\\InvalidException is never thrown in the try block\\.$#"
124+
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Elastica\\\\Document'' and Elastica\\Document will always evaluate to true\.$#'
125+
identifier: method.alreadyNarrowedType
126+
count: 2
127+
path: tests/DocumentTest.php
128+
129+
-
130+
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#'
131+
identifier: method.alreadyNarrowedType
132+
count: 6
133+
path: tests/DocumentTest.php
134+
135+
-
136+
message: '#^Dead catch \- Elastica\\Exception\\InvalidException is never thrown in the try block\.$#'
137+
identifier: catch.neverThrown
90138
count: 1
91139
path: tests/DocumentTest.php
92140

93141
-
94-
message: "#^Expression \"\\$document\\-\\>field5\" on a separate line does not do anything\\.$#"
142+
message: '#^Expression "\$document\-\>field5" on a separate line does not do anything\.$#'
143+
identifier: expr.resultUnused
95144
count: 1
96145
path: tests/DocumentTest.php
97146

98147
-
99-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
148+
message: '#^Unreachable statement \- code above always terminates\.$#'
149+
identifier: deadCode.unreachable
100150
count: 1
101151
path: tests/DocumentTest.php
102152

103153
-
104-
message: "#^Parameter \\#2 \\$name of class Elastica\\\\IndexTemplate constructor expects string, null given\\.$#"
154+
message: '#^Parameter \#2 \$name of class Elastica\\IndexTemplate constructor expects string, null given\.$#'
155+
identifier: argument.type
105156
count: 1
106157
path: tests/IndexTemplateTest.php
107158

108159
-
109-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
160+
message: '#^Unreachable statement \- code above always terminates\.$#'
161+
identifier: deadCode.unreachable
110162
count: 1
111163
path: tests/IndexTest.php
112164

113165
-
114-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
166+
message: '#^Unreachable statement \- code above always terminates\.$#'
167+
identifier: deadCode.unreachable
115168
count: 2
116169
path: tests/Multi/SearchTest.php
117170

118171
-
119-
message: "#^Parameter \\#1 \\$clauses of class Elastica\\\\Query\\\\SpanNear constructor expects array\\<Elastica\\\\Query\\\\AbstractSpanQuery\\>, array\\<int, Elastica\\\\Query\\\\Term\\> given\\.$#"
172+
message: '#^Parameter \#1 \$clauses of class Elastica\\Query\\SpanNear constructor expects array\<Elastica\\Query\\AbstractSpanQuery\>, array\<int, Elastica\\Query\\Term\> given\.$#'
173+
identifier: argument.type
120174
count: 1
121175
path: tests/Query/SpanNearTest.php
122176

123177
-
124-
message: "#^Parameter \\#1 \\$clauses of class Elastica\\\\Query\\\\SpanOr constructor expects array\\<Elastica\\\\Query\\\\AbstractSpanQuery\\>, array\\<int, Elastica\\\\Query\\\\Term\\> given\\.$#"
178+
message: '#^Parameter \#1 \$clauses of class Elastica\\Query\\SpanOr constructor expects array\<Elastica\\Query\\AbstractSpanQuery\>, array\<int, Elastica\\Query\\Term\> given\.$#'
179+
identifier: argument.type
125180
count: 1
126181
path: tests/Query/SpanOrTest.php
127182

128183
-
129-
message: "#^Parameter \\#1 \\$term of method Elastica\\\\Query\\\\Terms\\:\\:addTerm\\(\\) expects bool\\|float\\|int\\|string, stdClass given\\.$#"
184+
message: '#^Parameter \#1 \$term of method Elastica\\Query\\Terms\:\:addTerm\(\) expects bool\|float\|int\|string, stdClass given\.$#'
185+
identifier: argument.type
130186
count: 1
131187
path: tests/Query/TermsTest.php
132188

133189
-
134-
message: "#^Call to an undefined method ReflectionType\\:\\:getName\\(\\)\\.$#"
190+
message: '#^Call to an undefined method ReflectionType\:\:getName\(\)\.$#'
191+
identifier: method.notFound
135192
count: 2
136193
path: tests/QueryBuilder/DSL/AbstractDSLTestCase.php
137194

138195
-
139-
message: "#^Call to an undefined method ReflectionType\\:\\:isBuiltin\\(\\)\\.$#"
196+
message: '#^Call to an undefined method ReflectionType\:\:isBuiltin\(\)\.$#'
197+
identifier: method.notFound
140198
count: 1
141199
path: tests/QueryBuilder/DSL/AbstractDSLTestCase.php
142200

143201
-
144-
message: "#^Call to an undefined method Elastica\\\\QueryBuilder\\:\\:custom\\(\\)\\.$#"
202+
message: '#^Call to an undefined method Elastica\\QueryBuilder\:\:custom\(\)\.$#'
203+
identifier: method.notFound
145204
count: 1
146205
path: tests/QueryBuilderTest.php
147206

148207
-
149-
message: "#^Call to an undefined method Elastica\\\\QueryBuilder\\:\\:invalid\\(\\)\\.$#"
208+
message: '#^Call to an undefined method Elastica\\QueryBuilder\:\:invalid\(\)\.$#'
209+
identifier: method.notFound
150210
count: 1
151211
path: tests/QueryBuilderTest.php
152212

153213
-
154-
message: "#^Expression \"\\$index\\-\\>search\\('elastica search'\\)\\[3\\]\" on a separate line does not do anything\\.$#"
214+
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#'
215+
identifier: method.alreadyNarrowedType
155216
count: 1
156-
path: tests/ResultSetTest.php
217+
path: tests/QueryTest.php
157218

158219
-
159-
message: "#^Parameter \\#1 \\$indices of method Elastica\\\\Search\\:\\:addIndices\\(\\) expects array\\<Elastica\\\\Index\\>, array\\<int, stdClass\\> given\\.$#"
220+
message: '#^Parameter \#1 \$indices of method Elastica\\Search\:\:addIndices\(\) expects array\<Elastica\\Index\>, array\<int, stdClass\> given\.$#'
221+
identifier: argument.type
160222
count: 1
161223
path: tests/SearchTest.php
162224

163225
-
164-
message: "#^Parameter \\#1 \\$indices of method Elastica\\\\Search\\:\\:addIndicesByName\\(\\) expects array\\<string\\>, array\\<int, stdClass\\> given\\.$#"
226+
message: '#^Parameter \#1 \$indices of method Elastica\\Search\:\:addIndicesByName\(\) expects array\<string\>, array\<int, stdClass\> given\.$#'
227+
identifier: argument.type
165228
count: 1
166229
path: tests/SearchTest.php
167230

168231
-
169-
message: "#^Parameter \\#1 \\$suggestion of static method Elastica\\\\Suggest\\:\\:create\\(\\) expects Elastica\\\\Suggest\\|Elastica\\\\Suggest\\\\AbstractSuggest, Elastica\\\\Query\\\\BoolQuery given\\.$#"
232+
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Elastica\\\\Response'' and Elastica\\Response will always evaluate to true\.$#'
233+
identifier: method.alreadyNarrowedType
234+
count: 1
235+
path: tests/StatusTest.php
236+
237+
-
238+
message: '#^Parameter \#1 \$suggestion of static method Elastica\\Suggest\:\:create\(\) expects Elastica\\Suggest\|Elastica\\Suggest\\AbstractSuggest, Elastica\\Query\\BoolQuery given\.$#'
239+
identifier: argument.type
170240
count: 1
171241
path: tests/SuggestTest.php
172242

src/Client.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ public function getServerless(): bool
126126
* @throws NoNodeAvailableException if all the hosts are offline
127127
* @throws ClientResponseException if the status code of response is 4xx
128128
* @throws ServerResponseException if the status code of response is 5xx
129-
* @throws ClientException
130129
*/
131130
public function getVersion(): string
132131
{

src/Mapping.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ public function getParam(string $key)
145145
/**
146146
* Converts the mapping to an array.
147147
*
148-
* @throws InvalidException
149-
*
150148
* @return array Mapping as array
151149
*/
152150
public function toArray(): array

src/Snapshot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function restoreSnapshot($repository, $name, $options = [], $waitForCompl
233233
'repository' => $repository,
234234
'snapshot' => $name,
235235
'body' => $options,
236-
'wait_for_completion' => $waitForCompletion ? 'true' : 'false',
236+
'wait_for_completion' => (bool) $waitForCompletion,
237237
];
238238

239239
return $this->_client->toElasticaResponse(

tests/BulkTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,10 @@ public function testSend(): void
131131

132132
$this->assertEquals(3, $index->count());
133133

134-
try {
135-
$index->getDocument(3);
136-
$this->fail('Document #3 should be deleted');
137-
} catch (NotFoundException $e) {
138-
$this->assertTrue(true);
139-
}
134+
$this->expectException(NotFoundException::class);
135+
$this->expectExceptionMessage('doc id 3 not found');
136+
137+
$index->getDocument(3);
140138
}
141139

142140
#[Group('functional')]

0 commit comments

Comments
 (0)