Skip to content

Commit 79688b6

Browse files
committed
Update to PHPStan level 3; various fixes
1 parent bd74622 commit 79688b6

File tree

9 files changed

+99
-84
lines changed

9 files changed

+99
-84
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
],
1515

1616
"require": {
17-
"php": "8.1.* || 8.2.* || 8.3.* || 8.4.*",
17+
"php": "^8.1 || ^8.2 || ^8.3 || ^8.4",
1818
"composer-runtime-api": "^2.2"
1919
},
2020

phpstan.dist.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 1
2+
level: 3
33
paths:
44
- src
55
- tests

src/Behat/Gherkin/Node/OutlineNode.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class OutlineNode implements ScenarioInterface
3030
*/
3131
private $steps;
3232
/**
33-
* @var ExampleTableNode|ExampleTableNode[]
33+
* @var array<array-key, ExampleTableNode>
3434
*/
3535
private $tables;
3636
/**
@@ -52,7 +52,7 @@ class OutlineNode implements ScenarioInterface
5252
* @param string|null $title
5353
* @param string[] $tags
5454
* @param StepNode[] $steps
55-
* @param ExampleTableNode|ExampleTableNode[] $tables
55+
* @param ExampleTableNode|array<array-key, ExampleTableNode> $tables
5656
* @param string $keyword
5757
* @param int $line
5858
*/
@@ -69,11 +69,7 @@ public function __construct(
6969
$this->steps = $steps;
7070
$this->keyword = $keyword;
7171
$this->line = $line;
72-
if (!is_array($tables)) {
73-
$this->tables = [$tables];
74-
} else {
75-
$this->tables = $tables;
76-
}
72+
$this->tables = is_array($tables) ? $tables : [$tables];
7773
}
7874

7975
/**
@@ -197,7 +193,7 @@ public function getExamples()
197193
/**
198194
* Returns examples tables array for the outline.
199195
*
200-
* @return ExampleTableNode[]
196+
* @return array<array-key, ExampleTableNode>
201197
*/
202198
public function getExampleTables()
203199
{

src/Behat/Gherkin/Node/TableNode.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@
2323
*/
2424
class TableNode implements ArgumentInterface, IteratorAggregate
2525
{
26+
private array $table;
27+
2628
/**
27-
* @var array
28-
*/
29-
private $table;
30-
/**
31-
* @var int
29+
* @var array<array-key, int>
3230
*/
33-
private $maxLineLength = [];
31+
private array $maxLineLength = [];
3432

3533
/**
3634
* Initializes table.

tests/Behat/Gherkin/Filter/LineFilterTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class LineFilterTest extends FilterTestCase
2020
{
21-
public function testIsFeatureMatchFilter()
21+
public function testIsFeatureMatchFilter(): void
2222
{
2323
$feature = new FeatureNode(null, null, [], null, [], null, null, null, 1);
2424

@@ -32,7 +32,7 @@ public function testIsFeatureMatchFilter()
3232
$this->assertFalse($filter->isFeatureMatch($feature));
3333
}
3434

35-
public function testIsScenarioMatchFilter()
35+
public function testIsScenarioMatchFilter(): void
3636
{
3737
$scenario = new ScenarioNode(null, [], [], null, 2);
3838

@@ -54,7 +54,7 @@ public function testIsScenarioMatchFilter()
5454
$this->assertTrue($filter->isScenarioMatch($outline));
5555
}
5656

57-
public function testFilterFeatureScenario()
57+
public function testFilterFeatureScenario(): void
5858
{
5959
$filter = new LineFilter(2);
6060
$feature = $filter->filterFeature($this->getParsedFeature());
@@ -71,19 +71,20 @@ public function testFilterFeatureScenario()
7171
$this->assertCount(0, $scenarios = $feature->getScenarios());
7272
}
7373

74-
public function testFilterFeatureOutline()
74+
public function testFilterFeatureOutline(): void
7575
{
7676
$filter = new LineFilter(13);
7777
$feature = $filter->filterFeature($this->getParsedFeature());
78-
/* @var OutlineNode[] $scenarios */
7978
$this->assertCount(1, $scenarios = $feature->getScenarios());
8079
$this->assertSame('Scenario#3', $scenarios[0]->getTitle());
80+
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]);
8181
$this->assertCount(4, $scenarios[0]->getExampleTable()->getRows());
8282

8383
$filter = new LineFilter(20);
8484
$feature = $filter->filterFeature($this->getParsedFeature());
8585
$this->assertCount(1, $scenarios = $feature->getScenarios());
8686
$this->assertSame('Scenario#3', $scenarios[0]->getTitle());
87+
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]);
8788
$exampleTableNodes = $scenarios[0]->getExampleTables();
8889
$this->assertCount(1, $exampleTableNodes);
8990
$this->assertCount(2, $exampleTableNodes[0]->getRows());
@@ -97,6 +98,7 @@ public function testFilterFeatureOutline()
9798
$feature = $filter->filterFeature($this->getParsedFeature());
9899
$this->assertCount(1, $scenarios = $feature->getScenarios());
99100
$this->assertSame('Scenario#3', $scenarios[0]->getTitle());
101+
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]);
100102
$exampleTableNodes = $scenarios[0]->getExampleTables();
101103
$this->assertCount(1, $exampleTableNodes);
102104
$this->assertCount(2, $exampleTableNodes[0]->getRows());
@@ -110,6 +112,7 @@ public function testFilterFeatureOutline()
110112
$feature = $filter->filterFeature($this->getParsedFeature());
111113
$this->assertCount(1, $scenarios = $feature->getScenarios());
112114
$this->assertSame('Scenario#3', $scenarios[0]->getTitle());
115+
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]);
113116
$this->assertCount(1, $scenarios[0]->getExampleTable()->getRows());
114117
$this->assertSame([['action', 'outcome']], $scenarios[0]->getExampleTable()->getRows());
115118
}

tests/Behat/Gherkin/Filter/LineRangeFilterTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
use Behat\Gherkin\Node\FeatureNode;
1616
use Behat\Gherkin\Node\OutlineNode;
1717
use Behat\Gherkin\Node\ScenarioNode;
18+
use PHPUnit\Framework\Attributes\DataProvider;
1819

1920
class LineRangeFilterTest extends FilterTestCase
2021
{
21-
public function featureLineRangeProvider()
22+
public static function featureLineRangeProvider(): iterable
2223
{
2324
return [
2425
['1', '1', true],
@@ -29,18 +30,16 @@ public function featureLineRangeProvider()
2930
];
3031
}
3132

32-
/**
33-
* @dataProvider featureLineRangeProvider
34-
*/
35-
public function testIsFeatureMatchFilter($filterMinLine, $filterMaxLine, $expected)
33+
#[DataProvider('featureLineRangeProvider')]
34+
public function testIsFeatureMatchFilter(string $filterMinLine, string $filterMaxLine, bool $expected): void
3635
{
3736
$feature = new FeatureNode(null, null, [], null, [], null, null, null, 1);
3837

3938
$filter = new LineRangeFilter($filterMinLine, $filterMaxLine);
4039
$this->assertSame($expected, $filter->isFeatureMatch($feature));
4140
}
4241

43-
public function scenarioLineRangeProvider()
42+
public static function scenarioLineRangeProvider(): iterable
4443
{
4544
return [
4645
['1', '2', 1],
@@ -55,22 +54,20 @@ public function scenarioLineRangeProvider()
5554
];
5655
}
5756

58-
/**
59-
* @dataProvider scenarioLineRangeProvider
60-
*/
61-
public function testIsScenarioMatchFilter($filterMinLine, $filterMaxLine, $expectedNumberOfMatches)
57+
#[DataProvider('scenarioLineRangeProvider')]
58+
public function testIsScenarioMatchFilter(string $filterMinLine, string $filterMaxLine, int $expectedNumberOfMatches): void
6259
{
6360
$scenario = new ScenarioNode(null, [], [], null, 2);
6461
$outline = new OutlineNode(null, [], [], [new ExampleTableNode([], null)], null, 3);
6562

6663
$filter = new LineRangeFilter($filterMinLine, $filterMaxLine);
6764
$this->assertEquals(
6865
$expectedNumberOfMatches,
69-
intval($filter->isScenarioMatch($scenario)) + intval($filter->isScenarioMatch($outline))
66+
(int) $filter->isScenarioMatch($scenario) + (int) $filter->isScenarioMatch($outline)
7067
);
7168
}
7269

73-
public function testFilterFeatureScenario()
70+
public function testFilterFeatureScenario(): void
7471
{
7572
$filter = new LineRangeFilter(1, 3);
7673
$feature = $filter->filterFeature($this->getParsedFeature());
@@ -87,19 +84,20 @@ public function testFilterFeatureScenario()
8784
$this->assertCount(0, $scenarios = $feature->getScenarios());
8885
}
8986

90-
public function testFilterFeatureOutline()
87+
public function testFilterFeatureOutline(): void
9188
{
9289
$filter = new LineRangeFilter(12, 14);
9390
$feature = $filter->filterFeature($this->getParsedFeature());
94-
/* @var OutlineNode[] $scenarios */
9591
$this->assertCount(1, $scenarios = $feature->getScenarios());
9692
$this->assertSame('Scenario#3', $scenarios[0]->getTitle());
93+
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]);
9794
$this->assertFalse($scenarios[0]->hasExamples());
9895

9996
$filter = new LineRangeFilter(16, 21);
10097
$feature = $filter->filterFeature($this->getParsedFeature());
10198
$this->assertCount(1, $scenarios = $feature->getScenarios());
10299
$this->assertSame('Scenario#3', $scenarios[0]->getTitle());
100+
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]);
103101
$exampleTableNodes = $scenarios[0]->getExampleTables();
104102
$this->assertCount(1, $exampleTableNodes);
105103
$this->assertCount(3, $exampleTableNodes[0]->getRows());
@@ -114,6 +112,7 @@ public function testFilterFeatureOutline()
114112
$feature = $filter->filterFeature($this->getParsedFeature());
115113
$this->assertCount(1, $scenarios = $feature->getScenarios());
116114
$this->assertSame('Scenario#3', $scenarios[0]->getTitle());
115+
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]);
117116
$exampleTableNodes = $scenarios[0]->getExampleTables();
118117
$this->assertCount(2, $exampleTableNodes);
119118

@@ -137,6 +136,7 @@ public function testFilterFeatureOutline()
137136
$feature = $filter->filterFeature($this->getParsedFeature());
138137
$this->assertCount(1, $scenarios = $feature->getScenarios());
139138
$this->assertSame('Scenario#3', $scenarios[0]->getTitle());
139+
$this->assertInstanceOf(OutlineNode::class, $scenarios[0]);
140140
$exampleTableNodes = $scenarios[0]->getExampleTables();
141141
$this->assertCount(1, $exampleTableNodes);
142142
$this->assertCount(2, $exampleTableNodes[0]->getRows());

tests/Behat/Gherkin/Filter/TagFilterTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class TagFilterTest extends TestCase
2222
{
23-
public function testFilterFeature()
23+
public function testFilterFeature(): void
2424
{
2525
$feature = new FeatureNode(null, null, ['wip'], null, [], null, null, null, 1);
2626
$filter = new TagFilter('@wip');
@@ -46,7 +46,7 @@ public function testFilterFeature()
4646
$this->assertSame([$matchedScenario], $filteredFeature->getScenarios());
4747
}
4848

49-
public function testIsFeatureMatchFilter()
49+
public function testIsFeatureMatchFilter(): void
5050
{
5151
$feature = new FeatureNode(null, null, [], null, [], null, null, null, 1);
5252

@@ -95,7 +95,7 @@ public function testIsFeatureMatchFilter()
9595
$this->assertTrue($filter->isFeatureMatch($feature));
9696
}
9797

98-
public function testIsScenarioMatchFilter()
98+
public function testIsScenarioMatchFilter(): void
9999
{
100100
$feature = new FeatureNode(null, null, ['feature-tag'], null, [], null, null, null, 1);
101101
$scenario = new ScenarioNode(null, [], [], null, 2);
@@ -189,7 +189,7 @@ public function testIsScenarioMatchFilter()
189189
$this->assertFalse($tagFilter->isScenarioMatch($feature, $scenario), 'Tags from different examples tables');
190190
}
191191

192-
public function testFilterFeatureWithTaggedExamples()
192+
public function testFilterFeatureWithTaggedExamples(): void
193193
{
194194
$exampleTableNode1 = new ExampleTableNode([], null, ['etag1', 'etag2']);
195195
$exampleTableNode2 = new ExampleTableNode([], null, ['etag2', 'etag3']);
@@ -207,13 +207,13 @@ public function testFilterFeatureWithTaggedExamples()
207207
$tagFilter = new TagFilter('@etag1');
208208
$matched = $tagFilter->filterFeature($feature);
209209
$scenarioInterfaces = $matched->getScenarios();
210-
/* @noinspection PhpUndefinedMethodInspection */
210+
$this->assertInstanceOf(OutlineNode::class, $scenarioInterfaces[0]);
211211
$this->assertEquals([$exampleTableNode1], $scenarioInterfaces[0]->getExampleTables());
212212

213213
$tagFilter = new TagFilter('~@etag3');
214214
$matched = $tagFilter->filterFeature($feature);
215215
$scenarioInterfaces = $matched->getScenarios();
216-
/* @noinspection PhpUndefinedMethodInspection */
216+
$this->assertInstanceOf(OutlineNode::class, $scenarioInterfaces[0]);
217217
$this->assertEquals([$exampleTableNode1], $scenarioInterfaces[0]->getExampleTables());
218218

219219
$tagFilter = new TagFilter('@wip');
@@ -224,13 +224,13 @@ public function testFilterFeatureWithTaggedExamples()
224224
$tagFilter = new TagFilter('@wip&&@etag3');
225225
$matched = $tagFilter->filterFeature($feature);
226226
$scenarioInterfaces = $matched->getScenarios();
227-
/* @noinspection PhpUndefinedMethodInspection */
227+
$this->assertInstanceOf(OutlineNode::class, $scenarioInterfaces[0]);
228228
$this->assertEquals([$exampleTableNode2], $scenarioInterfaces[0]->getExampleTables());
229229

230230
$tagFilter = new TagFilter('@feature-tag&&@etag1&&@wip');
231231
$matched = $tagFilter->filterFeature($feature);
232232
$scenarioInterfaces = $matched->getScenarios();
233-
/* @noinspection PhpUndefinedMethodInspection */
233+
$this->assertInstanceOf(OutlineNode::class, $scenarioInterfaces[0]);
234234
$this->assertEquals([$exampleTableNode1], $scenarioInterfaces[0]->getExampleTables());
235235

236236
$tagFilter = new TagFilter('@feature-tag&&~@etag11111&&@wip');
@@ -241,7 +241,7 @@ public function testFilterFeatureWithTaggedExamples()
241241
$tagFilter = new TagFilter('@feature-tag&&~@etag1&&@wip');
242242
$matched = $tagFilter->filterFeature($feature);
243243
$scenarioInterfaces = $matched->getScenarios();
244-
/* @noinspection PhpUndefinedMethodInspection */
244+
$this->assertInstanceOf(OutlineNode::class, $scenarioInterfaces[0]);
245245
$this->assertEquals([$exampleTableNode2], $scenarioInterfaces[0]->getExampleTables());
246246

247247
$tagFilter = new TagFilter('@feature-tag&&@etag2');
@@ -272,13 +272,13 @@ public function testFilterFeatureWithTaggedExamples()
272272
$matched = $tagFilter->filterFeature($feature);
273273
$scenarioInterfaces = $matched->getScenarios();
274274
$this->assertCount(2, $scenarioInterfaces);
275-
/* @noinspection PhpUndefinedMethodInspection */
275+
$this->assertInstanceOf(OutlineNode::class, $scenarioInterfaces[0]);
276276
$this->assertEquals([$exampleTableNode2], $scenarioInterfaces[0]->getExampleTables());
277-
/* @noinspection PhpUndefinedMethodInspection */
277+
$this->assertInstanceOf(OutlineNode::class, $scenarioInterfaces[1]);
278278
$this->assertEquals([$exampleTableNode3], $scenarioInterfaces[1]->getExampleTables());
279279
}
280280

281-
public function testFilterWithWhitespaceIsDeprecated()
281+
public function testFilterWithWhitespaceIsDeprecated(): void
282282
{
283283
$this->expectDeprecationError();
284284

@@ -291,7 +291,7 @@ public function testFilterWithWhitespaceIsDeprecated()
291291
$this->assertEquals([$scenario], $scenarios);
292292
}
293293

294-
public function testTagFilterThatIsAllWhitespaceIsIgnored()
294+
public function testTagFilterThatIsAllWhitespaceIsIgnored(): void
295295
{
296296
$feature = new FeatureNode(null, null, [], null, [], null, null, null, 1);
297297
$tagFilter = new TagFilter('');
@@ -300,7 +300,7 @@ public function testTagFilterThatIsAllWhitespaceIsIgnored()
300300
$this->assertTrue($result);
301301
}
302302

303-
private function expectDeprecationError()
303+
private function expectDeprecationError(): void
304304
{
305305
set_error_handler(
306306
static function ($errno, $errstr) {
@@ -309,6 +309,6 @@ static function ($errno, $errstr) {
309309
},
310310
E_ALL
311311
);
312-
$this->expectException('Exception');
312+
$this->expectException(Exception::class);
313313
}
314314
}

0 commit comments

Comments
 (0)