Skip to content

Commit c14fefb

Browse files
authored
Merge branch 'master' into dependabot/github_actions/codecov/codecov-action-6
2 parents 8800e40 + 5a9abd1 commit c14fefb

4 files changed

Lines changed: 29 additions & 10 deletions

File tree

.php-cs-fixer.dist.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@
4040
'single_line_throw' => false,
4141
'ternary_to_null_coalescing' => true,
4242
'global_namespace_import' => false,
43+
'phpdoc_to_comment' => [ // Keep as a phpdoc if it contains the `@var` annotation
44+
'ignored_tags' => ['var'],
45+
],
4346
])
4447
->setFinder($finder);

bin/update_i18n

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ foreach ($gherkinLanguages as $lang => $keywords) {
2424
$words = [$words];
2525
}
2626

27+
assert(array_find($words, fn ($word) => !is_string($word)) === null, 'Expected $words to be an array of strings');
28+
/**
29+
* Here we force phpstan to recognise that we have narrowed the type of $words to a list of strings with the
30+
* assertion above. Otherwise it will report an error from the later `implode()` call that $words must be a
31+
* list<string>.
32+
*
33+
* There does not currently seem to be a way to force phpstan to detect this type narrowing at runtime
34+
* https://github.com/phpstan/phpstan/issues/14360
35+
*
36+
* @var array<string> $words
37+
*/
2738
if ($type === 'scenarioOutline') {
2839
$type = 'scenario_outline';
2940
}
@@ -32,7 +43,6 @@ foreach ($gherkinLanguages as $lang => $keywords) {
3243
$formattedKeywords = [];
3344

3445
foreach ($words as $word) {
35-
assert(is_string($word));
3646
$formattedWord = trim($word);
3747

3848
if ($formattedWord === $word) {
@@ -45,12 +55,14 @@ foreach ($gherkinLanguages as $lang => $keywords) {
4555
$words = $formattedKeywords;
4656
}
4757

48-
usort($words, static function ($type1, $type2) {
49-
assert(is_string($type1));
50-
assert(is_string($type2));
58+
foreach ($words as $word) {
59+
assert(is_string($word));
60+
}
5161

52-
return [mb_strlen($type2, 'utf8'), $type1] <=> [mb_strlen($type1, 'utf8'), $type2];
53-
});
62+
usort(
63+
$words,
64+
static fn (string $type1, string $type2) => [mb_strlen($type2, 'utf8'), $type1] <=> [mb_strlen($type1, 'utf8'), $type2]
65+
);
5466

5567
$langMessages[$type] = implode('|', $words);
5668
}

src/Gherkin.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ public function resolveLoader(mixed $resource)
151151
{
152152
foreach ($this->loaders as $loader) {
153153
if ($loader->supports($resource)) {
154+
/**
155+
* If the loader supports the provided resource, then it can safely be typed as
156+
* LoaderInterface<ResourceType>.
157+
*
158+
* @var LoaderInterface<TResourceType> $loader
159+
*/
154160
return $loader;
155161
}
156162
}

src/Loader/LoaderInterface.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ interface LoaderInterface
2424
/**
2525
* Checks if current loader supports provided resource.
2626
*
27-
* @template TSupportedResourceType
27+
* @param mixed $resource Resource to load
2828
*
29-
* @param TSupportedResourceType $resource Resource to load
30-
*
31-
* @phpstan-assert-if-true =LoaderInterface<TSupportedResourceType> $this
29+
* @phpstan-assert-if-true =TResourceType $resource
3230
*
3331
* @return bool
3432
*/

0 commit comments

Comments
 (0)