Skip to content

Commit ada1b6b

Browse files
committed
bump phpstan to master. Fixed ignored errors
1 parent e2ce1d2 commit ada1b6b

30 files changed

+85
-111
lines changed

.github/workflows/push.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
all-build-${{ hashFiles('**/composer.lock') }}
132132
all-build-
133133
- name: Code style check
134-
uses: phpDocumentor/coding-standard@v1.0.0
134+
uses: phpDocumentor/coding-standard@master
135135
with:
136136
args: -s
137137

@@ -153,7 +153,7 @@ jobs:
153153
env:
154154
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155155
with:
156-
args: analyse src --level max --configuration phpstan.neon
156+
args: analyse src --configuration phpstan.neon
157157

158158
psalm:
159159
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-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ includes:
33
- /composer/vendor/phpstan/phpstan-webmozart-assert/extension.neon
44

55
parameters:
6+
level: max
67
ignoreErrors:
7-
# false positive
8-
- '#Method phpDocumentor\Reflection\DocBlock\Tags\Method::filterArguments() should return array<array> but returns array<array|string>#'
8+
- '#Call to static method Webmozart\\Assert\\Assert::implementsInterface\(\) with class-string#'

psalm.xml

+7
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@
1414

1515
<issueHandlers>
1616
<LessSpecificReturnType errorLevel="info" />
17+
18+
<RedundantConditionGivenDocblockType>
19+
<errorLevel type="info">
20+
<!-- Psalm is very strict and believe that because we documented a type, it is redundant to assert it -->
21+
<file name="src/DocBlock/StandardTagFactory.php"/>
22+
</errorLevel>
23+
</RedundantConditionGivenDocblockType>
1724
</issueHandlers>
1825
</psalm>

src/DocBlock.php

-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ public function getTagsByName(string $name) : array
150150
{
151151
$result = [];
152152

153-
/** @var Tag $tag */
154153
foreach ($this->getTags() as $tag) {
155154
if ($tag->getName() !== $name) {
156155
continue;
@@ -169,7 +168,6 @@ public function getTagsByName(string $name) : array
169168
*/
170169
public function hasTag(string $name) : bool
171170
{
172-
/** @var Tag $tag */
173171
foreach ($this->getTags() as $tag) {
174172
if ($tag->getName() === $name) {
175173
return true;

src/DocBlock/DescriptionFactory.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use phpDocumentor\Reflection\Types\Context as TypeContext;
1717
use Webmozart\Assert\Assert;
18-
use const PREG_SPLIT_DELIM_CAPTURE;
1918
use function count;
2019
use function explode;
2120
use function implode;
@@ -27,6 +26,7 @@
2726
use function strpos;
2827
use function substr;
2928
use function trim;
29+
use const PREG_SPLIT_DELIM_CAPTURE;
3030

3131
/**
3232
* Creates a new Description object given a body of text.
@@ -128,6 +128,7 @@ private function lex(string $contents) : array
128128
PREG_SPLIT_DELIM_CAPTURE
129129
);
130130
Assert::isArray($parts);
131+
131132
return $parts;
132133
}
133134

src/DocBlock/ExampleFinder.php

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

1616
use phpDocumentor\Reflection\DocBlock\Tags\Example;
17-
use const DIRECTORY_SEPARATOR;
1817
use function array_slice;
1918
use function file;
2019
use function getcwd;
@@ -23,6 +22,7 @@
2322
use function rtrim;
2423
use function sprintf;
2524
use function trim;
25+
use const DIRECTORY_SEPARATOR;
2626

2727
/**
2828
* Class used to find an example file's location based on a given ExampleDescriptor.
@@ -122,6 +122,7 @@ private function getExampleFileContents(string $filename) : ?array
122122
}
123123

124124
$lines = $normalizedPath && is_readable($normalizedPath) ? file($normalizedPath) : false;
125+
125126
return $lines !== false ? $lines : null;
126127
}
127128

src/DocBlock/Serializer.php

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public function getDocComment(DocBlock $docblock) : string
9494
}
9595

9696
$comment = $this->addTagBlock($docblock, $wrapLength, $indent, $comment);
97+
9798
return $comment . $indent . ' */';
9899
}
99100

@@ -127,6 +128,7 @@ private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, ?int $wra
127128
: '');
128129
if ($wrapLength !== null) {
129130
$text = wordwrap($text, $wrapLength);
131+
130132
return $text;
131133
}
132134

src/DocBlock/StandardTagFactory.php

+8-17
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
{
@@ -137,9 +137,6 @@ public function __construct(FqsenResolver $fqsenResolver, ?array $tagHandlers =
137137
$this->addService($fqsenResolver, FqsenResolver::class);
138138
}
139139

140-
/**
141-
* {@inheritDoc}
142-
*/
143140
public function create(string $tagLine, ?TypeContext $context = null) : Tag
144141
{
145142
if (!$context) {
@@ -152,29 +149,22 @@ public function create(string $tagLine, ?TypeContext $context = null) : Tag
152149
}
153150

154151
/**
155-
* {@inheritDoc}
152+
* @param mixed $value
156153
*/
157154
public function addParameter(string $name, $value) : void
158155
{
159156
$this->serviceLocator[$name] = $value;
160157
}
161158

162-
/**
163-
* {@inheritDoc}
164-
*/
165159
public function addService(object $service, ?string $alias = null) : void
166160
{
167161
$this->serviceLocator[$alias ?: get_class($service)] = $service;
168162
}
169163

170-
/**
171-
* {@inheritDoc}
172-
*/
173164
public function registerTagHandler(string $tagName, string $handler) : void
174165
{
175166
Assert::stringNotEmpty($tagName);
176167
Assert::classExists($handler);
177-
/** @var object $handler stupid hack to make phpstan happy. */
178168
Assert::implementsInterface($handler, StaticMethod::class);
179169

180170
if (strpos($tagName, '\\') && $tagName[0] !== '\\') {
@@ -220,9 +210,10 @@ private function createTag(string $body, string $name, TypeContext $context) : T
220210
);
221211

222212
try {
223-
/** @var callable $callable */
224213
$callable = [$handlerClassName, 'create'];
225-
$tag = call_user_func_array($callable, $arguments);
214+
Assert::isCallable($callable);
215+
$tag = call_user_func_array($callable, $arguments);
216+
226217
return $tag ?? InvalidTag::create($body, $name);
227218
} catch (InvalidArgumentException $e) {
228219
return InvalidTag::create($body, $name)->withError($e);

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/Author.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
namespace phpDocumentor\Reflection\DocBlock\Tags;
1515

1616
use InvalidArgumentException;
17-
use const FILTER_VALIDATE_EMAIL;
1817
use function filter_var;
1918
use function preg_match;
2019
use function strlen;
2120
use function trim;
21+
use const FILTER_VALIDATE_EMAIL;
2222

2323
/**
2424
* Reflection class for an {@}author tag in a Docblock.

src/DocBlock/Tags/Covers.php

-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ public function __construct(Fqsen $refers, ?Description $description = null)
4141
$this->description = $description;
4242
}
4343

44-
/**
45-
* {@inheritdoc}
46-
*/
4744
public static function create(
4845
string $body,
4946
?DescriptionFactory $descriptionFactory = null,

src/DocBlock/Tags/Deprecated.php

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public static function create(
7575
}
7676

7777
Assert::notNull($descriptionFactory);
78+
7879
return new static(
7980
$matches[1],
8081
$descriptionFactory->create($matches[2] ?? '', $context)

src/DocBlock/Tags/Example.php

-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ public function getDescription() : ?string
8282
return $this->content;
8383
}
8484

85-
/**
86-
* {@inheritdoc}
87-
*/
8885
public static function create(string $body) : ?Tag
8986
{
9087
// File component: File path in quotes or File URI / Source information

src/DocBlock/Tags/Link.php

-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ public function __construct(string $link, ?Description $description = null)
3939
$this->description = $description;
4040
}
4141

42-
/**
43-
* {@inheritdoc}
44-
*/
4542
public static function create(
4643
string $body,
4744
?DescriptionFactory $descriptionFactory = null,

src/DocBlock/Tags/Method.php

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

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

5053
/** @var bool */
@@ -54,9 +57,9 @@ final class Method extends BaseTag implements Factory\StaticMethod
5457
private $returnType;
5558

5659
/**
57-
* @param mixed[][] $arguments
60+
* @param array<int, array<string, Type|string>> $arguments
5861
*
59-
* @psalm-param array<int, array<string, string|Type>|string> $arguments
62+
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
6063
*/
6164
public function __construct(
6265
string $methodName,
@@ -78,9 +81,6 @@ public function __construct(
7881
$this->description = $description;
7982
}
8083

81-
/**
82-
* {@inheritdoc}
83-
*/
8484
public static function create(
8585
string $body,
8686
?TypeResolver $typeResolver = null,
@@ -137,7 +137,7 @@ public static function create(
137137
return null;
138138
}
139139

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

142142
$static = $static === 'static';
143143

@@ -148,9 +148,11 @@ public static function create(
148148
$returnType = $typeResolver->resolve($returnType, $context);
149149
$description = $descriptionFactory->create($description, $context);
150150

151-
if ($arguments !== '') {
152-
$arguments = explode(',', $arguments);
153-
foreach ($arguments as &$argument) {
151+
/** @phpstan-var array<int, array{name: string, type: Type}> $arguments */
152+
$arguments = [];
153+
if ($argumentLines !== '') {
154+
$argumentsExploded = explode(',', $argumentLines);
155+
foreach ($argumentsExploded as $argument) {
154156
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
155157
if ($argument[0][0] === '$') {
156158
$argumentName = substr($argument[0], 1);
@@ -164,10 +166,8 @@ public static function create(
164166
}
165167
}
166168

167-
$argument = ['name' => $argumentName, 'type' => $argumentType];
169+
$arguments[] = ['name' => $argumentName, 'type' => $argumentType];
168170
}
169-
} else {
170-
$arguments = [];
171171
}
172172

173173
return new static($methodName, $arguments, $returnType, $static, $description);
@@ -182,7 +182,9 @@ public function getMethodName() : string
182182
}
183183

184184
/**
185-
* @return string[][]
185+
* @return array<int, array<string, Type|string>>
186+
*
187+
* @phpstan-return array<int, array{name: string, type: Type}>
186188
*/
187189
public function getArguments() : array
188190
{
@@ -223,8 +225,8 @@ public function __toString() : string
223225
*
224226
* @return mixed[][]
225227
*
226-
* @psalm-param array<int, array<string, string|Type>|string> $arguments
227-
* @psalm-return array<int, array<string, string|Type>> $arguments
228+
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
229+
* @phpstan-return array<int, array{name: string, type: Type}>
228230
*/
229231
private function filterArguments(array $arguments = []) : array
230232
{

0 commit comments

Comments
 (0)