Skip to content

Commit c02e53f

Browse files
committed
bump phpstan to master. Fixed ignored errors
1 parent a488071 commit c02e53f

12 files changed

+43
-27
lines changed

.github/workflows/push.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ jobs:
149149
env:
150150
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151151
with:
152-
args: analyse src --level max --configuration phpstan.neon
152+
args: analyse src --configuration phpstan.neon
153153

154154
psalm:
155155
runs-on: ubuntu-latest

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ phpcbf:
2121

2222
.PHONY: phpstan
2323
phpstan:
24-
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpstan-ga:latest analyse src --no-progress --level max --configuration phpstan.neon
24+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpstan-ga:latest analyse src --no-progress --configuration phpstan.neon
2525

2626
.PHONY: psaml
2727
psalm:

phpstan.neon

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ includes:
33
- /composer/vendor/phpstan/phpstan-webmozart-assert/extension.neon
44

55
parameters:
6-
ignoreErrors:
7-
# false positive
8-
- '#Method phpDocumentor\Reflection\DocBlock\Tags\Method::filterArguments() should return array<array> but returns array<array|string>#'
6+
level: max
7+

src/DocBlock/StandardTagFactory.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ final class StandardTagFactory implements TagFactory
7171
public const REGEX_TAGNAME = '[\w\-\_\\\\:]+';
7272

7373
/**
74-
* @var string[] An array with a tag as a key, and an
75-
* FQCN to a class that handles it as an array value.
74+
* @var array<class-string<StaticMethod>> An array with a tag as a key, and an
75+
* FQCN to a class that handles it as an array value.
7676
*/
7777
private $tagHandlerMappings = [
7878
'author' => Author::class,
@@ -97,7 +97,7 @@ final class StandardTagFactory implements TagFactory
9797
];
9898

9999
/**
100-
* @var string[] An array with a anotation s a key, and an
100+
* @var array<class-string<StaticMethod>> An array with a anotation s a key, and an
101101
* FQCN to a class that handles it as an array value.
102102
*/
103103
private $annotationMappings = [];
@@ -125,7 +125,7 @@ final class StandardTagFactory implements TagFactory
125125
*
126126
* @see self::registerTagHandler() to add a new tag handler to the existing default list.
127127
*
128-
* @param string[] $tagHandlers
128+
* @param array<class-string<StaticMethod>> $tagHandlers
129129
*/
130130
public function __construct(FqsenResolver $fqsenResolver, ?array $tagHandlers = null)
131131
{
@@ -176,6 +176,7 @@ public function registerTagHandler(string $tagName, string $handler) : void
176176
Assert::classExists($handler);
177177
/** @var object $handler stupid hack to make phpstan happy. */
178178
Assert::implementsInterface($handler, StaticMethod::class);
179+
/** @var class-string<StaticMethod> $handler second stupid hack to make phpstan happy. */
179180

180181
if (strpos($tagName, '\\') && $tagName[0] !== '\\') {
181182
throw new InvalidArgumentException(

src/DocBlock/TagFactory.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\Reflection\DocBlock;
1515

1616
use InvalidArgumentException;
17+
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
1718
use phpDocumentor\Reflection\Types\Context as TypeContext;
1819

1920
interface TagFactory
@@ -69,9 +70,9 @@ public function addService(object $service) : void;
6970
* to register the name of a tag with the FQCN of a 'Tag Handler'. The Tag handler should implement
7071
* the {@see Tag} interface (and thus the create method).
7172
*
72-
* @param string $tagName Name of tag to register a handler for. When registering a namespaced tag,
73-
* the full name, along with a prefixing slash MUST be provided.
74-
* @param string $handler FQCN of handler.
73+
* @param string $tagName Name of tag to register a handler for. When registering a namespaced
74+
* tag, the full name, along with a prefixing slash MUST be provided.
75+
* @param class-string<StaticMethod> $handler FQCN of handler.
7576
*
7677
* @throws InvalidArgumentException If the tag name is not a string.
7778
* @throws InvalidArgumentException If the tag name is namespaced (contains backslashes) but

src/DocBlock/Tags/Method.php

+20-14
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ final class Method extends BaseTag implements Factory\StaticMethod
4444
/** @var string */
4545
private $methodName = '';
4646

47-
/** @var string[][] */
47+
/**
48+
* @var array<int, array<string, Type|string>>
49+
*
50+
* @phpstan-var array<int, array{name: string, type: Type}>
51+
*/
4852
private $arguments = [];
4953

5054
/** @var bool */
@@ -54,9 +58,9 @@ final class Method extends BaseTag implements Factory\StaticMethod
5458
private $returnType;
5559

5660
/**
57-
* @param mixed[][] $arguments
61+
* @param array<int, array<string, Type|string>> $arguments
5862
*
59-
* @psalm-param array<int, array<string, string|Type>|string> $arguments
63+
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
6064
*/
6165
public function __construct(
6266
string $methodName,
@@ -137,7 +141,7 @@ public static function create(
137141
return null;
138142
}
139143

140-
[, $static, $returnType, $methodName, $arguments, $description] = $matches;
144+
[, $static, $returnType, $methodName, $argumentLines, $description] = $matches;
141145

142146
$static = $static === 'static';
143147

@@ -147,10 +151,12 @@ public static function create(
147151

148152
$returnType = $typeResolver->resolve($returnType, $context);
149153
$description = $descriptionFactory->create($description, $context);
150-
151-
if ($arguments !== '') {
152-
$arguments = explode(',', $arguments);
153-
foreach ($arguments as &$argument) {
154+
155+
/** @phpstan-var array<int, array{name: string, type: Type}> $arguments */
156+
$arguments = [];
157+
if ($argumentLines !== '') {
158+
$argumentsExploded = explode(',', $argumentLines);
159+
foreach ($argumentsExploded as $argument) {
154160
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
155161
if ($argument[0][0] === '$') {
156162
$argumentName = substr($argument[0], 1);
@@ -164,10 +170,8 @@ public static function create(
164170
}
165171
}
166172

167-
$argument = ['name' => $argumentName, 'type' => $argumentType];
173+
$arguments[] = ['name' => $argumentName, 'type' => $argumentType];
168174
}
169-
} else {
170-
$arguments = [];
171175
}
172176

173177
return new static($methodName, $arguments, $returnType, $static, $description);
@@ -182,7 +186,9 @@ public function getMethodName() : string
182186
}
183187

184188
/**
185-
* @return string[][]
189+
* @return array<int, array<string, Type|string>>
190+
*
191+
* @phpstan-return array<int, array{name: string, type: Type}>
186192
*/
187193
public function getArguments() : array
188194
{
@@ -223,8 +229,8 @@ public function __toString() : string
223229
*
224230
* @return mixed[][]
225231
*
226-
* @psalm-param array<int, array<string, string|Type>|string> $arguments
227-
* @psalm-return array<int, array<string, string|Type>> $arguments
232+
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
233+
* @phpstan-return array<int, array{name: string, type: Type}>
228234
*/
229235
private function filterArguments(array $arguments = []) : array
230236
{

src/DocBlock/Tags/Param.php

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public static function create(
6969

7070
$type = null;
7171
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
72+
Assert::isArray($parts);
7273
$variableName = '';
7374
$isVariadic = false;
7475

src/DocBlock/Tags/Property.php

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static function create(
6262
[$firstPart, $body] = self::extractTypeFromBody($body);
6363
$type = null;
6464
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
65+
Assert::isArray($parts);
6566
$variableName = '';
6667

6768
// if the first item that is encountered is not a variable; it is a type

src/DocBlock/Tags/PropertyRead.php

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static function create(
6262
[$firstPart, $body] = self::extractTypeFromBody($body);
6363
$type = null;
6464
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
65+
Assert::isArray($parts);
6566
$variableName = '';
6667

6768
// if the first item that is encountered is not a variable; it is a type

src/DocBlock/Tags/PropertyWrite.php

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static function create(
6262
[$firstPart, $body] = self::extractTypeFromBody($body);
6363
$type = null;
6464
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
65+
Assert::isArray($parts);
6566
$variableName = '';
6667

6768
// if the first item that is encountered is not a variable; it is a type

src/DocBlock/Tags/Var_.php

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static function create(
6262
[$firstPart, $body] = self::extractTypeFromBody($body);
6363

6464
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
65+
Assert::isArray($parts);
6566
$type = null;
6667
$variableName = '';
6768

src/DocBlockFactory.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
1919
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
2020
use phpDocumentor\Reflection\DocBlock\TagFactory;
21+
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
2122
use Webmozart\Assert\Assert;
2223
use function array_shift;
2324
use function count;
@@ -51,7 +52,7 @@ public function __construct(DescriptionFactory $descriptionFactory, TagFactory $
5152
/**
5253
* Factory method for easy instantiation.
5354
*
54-
* @param string[] $additionalTags
55+
* @param array<class-string<StaticMethod>> $additionalTags
5556
*/
5657
public static function createInstance(array $additionalTags = []) : self
5758
{
@@ -106,6 +107,9 @@ public function create($docblock, ?Types\Context $context = null, ?Location $loc
106107
);
107108
}
108109

110+
/**
111+
* @param class-string<StaticMethod> $handler
112+
*/
109113
public function registerTagHandler(string $tagName, string $handler) : void
110114
{
111115
$this->tagFactory->registerTagHandler($tagName, $handler);

0 commit comments

Comments
 (0)