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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 8 additions & 17 deletions
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

Lines changed: 4 additions & 3 deletions
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

0 commit comments

Comments
 (0)