Skip to content

Commit c14c018

Browse files
committed
Make static anlisys pass
1 parent 09e086e commit c14c018

24 files changed

+143
-96
lines changed

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.PHONY: install-phive
2+
install-phive:
3+
mkdir tools; \
4+
wget -O tools/phive.phar https://phar.io/releases/phive.phar; \
5+
wget -O tools/phive.phar.asc https://phar.io/releases/phive.phar.asc; \
6+
gpg --keyserver pool.sks-keyservers.net --recv-keys 0x9D8A98B29B2D5D79; \
7+
gpg --verify tools/phive.phar.asc tools/phive.phar; \
8+
chmod +x tools/phive.phar
9+
10+
.PHONY: setup
11+
setup: install-phive
12+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phar-ga:latest php tools/phive.phar install --force-accept-unsigned
13+
14+
.PHONY: phpcs
15+
phpcs:
16+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpcs-ga:latest -d memory_limit=1024M
17+
18+
.PHONY: phpstan
19+
phpstan:
20+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpstan-ga:latest analyse src --debug --no-progress --level max --configuration phpstan.neon
21+
22+
.PHONY: psaml
23+
psalm:
24+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project mickaelandrieu/psalm-ga
25+
26+
.PHONY: test
27+
test:
28+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.2 tools/phpunit
29+
30+
.PHONY: pre-commit-test
31+
pre-commit-test: test phpcs phpstan psalm
32+

composer.lock

Lines changed: 9 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phive.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phive xmlns="https://phar.io/phive">
3+
<phar name="phpunit" version="^8.4.3" installed="8.4.3" location="./tools/phpunit" copy="true"/>
4+
<phar name="phpstan" version="^0.9.1" installed="0.10.2" location="./tools/phpstan" copy="true"/>
5+
</phive>

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ parameters:
66
ignoreErrors:
77
# false positive
88
- '#Method phpDocumentor\Reflection\DocBlock\Tags\Method::filterArguments() should return array<array> but returns array<array|string>#'
9-
- "~Parameter #1 $function of function call_user_func_array expects callable(): mixed, array(string, 'create') given.~"
10-
- '#Cannot call method render\(\) on phpDocumentor\\Reflection\\DocBlock\\Description\|string#'

phpunit.xml.dist

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<phpunit
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
46
colors="true"
5-
checkForUnintentionallyCoveredCode="true"
67
beStrictAboutOutputDuringTests="true"
78
forceCoversAnnotation="true"
89
verbose="true"
@@ -20,17 +21,10 @@
2021
<whitelist>
2122
<directory suffix=".php">./src/</directory>
2223
</whitelist>
23-
<blacklist>
24-
<directory>./vendor/</directory>
25-
</blacklist>
2624
</filter>
2725
<logging>
2826
<log type="coverage-html"
29-
title="phpDocumentor Reflection DocBlock"
3027
target="build/coverage"
31-
charset="UTF-8"
32-
yui="true"
33-
highlight="false"
3428
lowUpperBound="35"
3529
highLowerBound="70"/>
3630
</logging>

src/DocBlock/StandardTagFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ public function addService(object $service, ?string $alias = null) : void
177177
public function registerTagHandler(string $tagName, string $handler) : void
178178
{
179179
Assert::stringNotEmpty($tagName);
180-
Assert::stringNotEmpty($handler);
181180
Assert::classExists($handler);
181+
/** @var object $handler stupid hack to make phpstan happy. */
182182
Assert::implementsInterface($handler, StaticMethod::class);
183183

184184
if (strpos($tagName, '\\') && $tagName[0] !== '\\') {
@@ -224,7 +224,9 @@ private function createTag(string $body, string $name, TypeContext $context) : ?
224224
);
225225

226226
try {
227-
return call_user_func_array([$handlerClassName, 'create'], $arguments);
227+
/** @var callable $callable */
228+
$callable = [$handlerClassName, 'create'];
229+
return call_user_func_array($callable, $arguments);
228230
} catch (InvalidArgumentException $e) {
229231
return null;
230232
}

src/DocBlock/Tags/BaseTag.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class BaseTag implements DocBlock\Tag
2424
/** @var string Name of the tag */
2525
protected $name = '';
2626

27-
/** @var Description|string|null Description of the tag. */
27+
/** @var Description|null Description of the tag. */
2828
protected $description;
2929

3030
/**
@@ -37,10 +37,7 @@ public function getName() : string
3737
return $this->name;
3838
}
3939

40-
/**
41-
* @return Description|string|null
42-
*/
43-
public function getDescription()
40+
public function getDescription() : ?Description
4441
{
4542
return $this->description;
4643
}

src/DocBlock/Tags/Deprecated.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ public function getVersion() : ?string
9494
*/
9595
public function __toString() : string
9696
{
97-
return $this->version . ($this->description ? ' ' . $this->description->render() : '');
97+
return ($this->version ?? '') . ($this->description ? ' ' . $this->description->render() : '');
9898
}
9999
}

src/DocBlock/Tags/Example.php

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace phpDocumentor\Reflection\DocBlock\Tags;
1515

16-
use phpDocumentor\Reflection\DocBlock\Description;
1716
use phpDocumentor\Reflection\DocBlock\Tag;
1817
use Webmozart\Assert\Assert;
1918
use function array_key_exists;
@@ -26,7 +25,7 @@
2625
/**
2726
* Reflection class for a {@}example tag in a Docblock.
2827
*/
29-
final class Example extends BaseTag
28+
final class Example implements Tag
3029
{
3130
/** @var string Path to a file to use as an example. May also be an absolute URI. */
3231
private $filePath;
@@ -43,10 +42,10 @@ final class Example extends BaseTag
4342
/** @var int */
4443
private $lineCount;
4544

46-
/**
47-
* @param string|Description|null $description
48-
*/
49-
public function __construct(string $filePath, bool $isURI, int $startingLine, int $lineCount, $description)
45+
/** @var string|null */
46+
private $content;
47+
48+
public function __construct(string $filePath, bool $isURI, int $startingLine, int $lineCount, ?string $content)
5049
{
5150
Assert::notEmpty($filePath);
5251
Assert::greaterThanEq($startingLine, 0);
@@ -55,31 +54,32 @@ public function __construct(string $filePath, bool $isURI, int $startingLine, in
5554
$this->filePath = $filePath;
5655
$this->startingLine = $startingLine;
5756
$this->lineCount = $lineCount;
58-
$this->name = 'example';
59-
if ($description !== null) {
60-
$this->description = trim((string) $description);
57+
if ($content !== null) {
58+
$this->content = trim((string) $content);
6159
}
6260

6361
$this->isURI = $isURI;
6462
}
6563

66-
/**
67-
* {@inheritdoc}
68-
*/
69-
public function getContent()
64+
public function getContent() : string
7065
{
71-
if ($this->description === null) {
66+
if ($this->content === null) {
7267
$filePath = '"' . $this->filePath . '"';
7368
if ($this->isURI) {
7469
$filePath = $this->isUriRelative($this->filePath)
7570
? str_replace('%2F', '/', rawurlencode($this->filePath))
7671
: $this->filePath;
7772
}
7873

79-
return trim($filePath . ' ' . parent::getDescription());
74+
return trim($filePath);
8075
}
8176

82-
return $this->description;
77+
return $this->content;
78+
}
79+
80+
public function getDescription() : ?string
81+
{
82+
return $this->content;
8383
}
8484

8585
/**
@@ -121,7 +121,7 @@ public static function create(string $body) : ?Tag
121121
}
122122

123123
return new static(
124-
$filePath ?? $fileUri,
124+
$filePath ?? ($fileUri ?? ''),
125125
$fileUri !== null,
126126
$startingLine,
127127
$lineCount,
@@ -145,7 +145,7 @@ public function getFilePath() : string
145145
*/
146146
public function __toString() : string
147147
{
148-
return $this->filePath . ($this->description ? ' ' . $this->description : '');
148+
return $this->filePath . ($this->content ? ' ' . $this->content : '');
149149
}
150150

151151
/**
@@ -165,4 +165,18 @@ public function getLineCount() : int
165165
{
166166
return $this->lineCount;
167167
}
168+
169+
public function getName() : string
170+
{
171+
return 'example';
172+
}
173+
174+
public function render(?Formatter $formatter = null) : string
175+
{
176+
if ($formatter === null) {
177+
$formatter = new Formatter\PassthroughFormatter();
178+
}
179+
180+
return $formatter->format($this);
181+
}
168182
}

src/DocBlock/Tags/Generic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Parses a tag definition for a DocBlock.
2626
*/
27-
class Generic extends BaseTag implements Factory\StaticMethod
27+
final class Generic extends BaseTag implements Factory\StaticMethod
2828
{
2929
/**
3030
* Parses a tag and populates the member variables.

0 commit comments

Comments
 (0)