Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"phpstan/phpstan-mockery": "^1.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-webmozart-assert": "^1.2",
"psalm/phar": "^5.26"
"psalm/phar": "^5.26",
"shipmonk/dead-code-detector": "^0.5.1"
},
"autoload": {
"psr-4": {
Expand Down
71 changes: 70 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
parameters:
ignoreErrors:
-
message: "#^Unused phpDocumentor\\\\Reflection\\\\DocBlock\\\\ExampleFinder\\:\\:getExampleDirectories$#"
count: 1
path: src/DocBlock/ExampleFinder.php

-
message: "#^Unused phpDocumentor\\\\Reflection\\\\DocBlock\\\\ExampleFinder\\:\\:setExampleDirectories$#"
count: 1
path: src/DocBlock/ExampleFinder.php

-
message: "#^Unused phpDocumentor\\\\Reflection\\\\DocBlock\\\\ExampleFinder\\:\\:setSourceDirectory$#"
count: 1
path: src/DocBlock/ExampleFinder.php

-
message: "#^Unused phpDocumentor\\\\Reflection\\\\DocBlock\\\\Tags\\\\Factory\\\\MethodParameterFactory\\:\\:formatNull$#"
count: 1
path: src/DocBlock/Tags/Factory/MethodParameterFactory.php
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
includes:
- phpstan-baseline.neon

parameters:
level: max
ignoreErrors:
- '#Method phpDocumentor\\Reflection\\DocBlock\\StandardTagFactory::createTag\(\) should return phpDocumentor\\Reflection\\DocBlock\\Tag but returns mixed#'
- '#Offset 2 on array\{string, 28, int\} on left side of \?\? always exists and is not nullable\.#'
-
path: src/DocBlockFactoryInterface.php
identifier: shipmonk.deadMethod
-
path: src/DocBlock/TagFactory.php
identifier: shipmonk.deadMethod
paths:
- src
- tests/unit
59 changes: 22 additions & 37 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
colors="true"
convertDeprecationsToExceptions="false"
beStrictAboutOutputDuringTests="false"
forceCoversAnnotation="true"
verbose="true"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="unit">
<directory>./tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/integration</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html"
target="build/coverage"
lowUpperBound="35"
highLowerBound="70"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<listeners>
<listener
class="Mockery\Adapter\Phpunit\TestListener"
file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"
/>
</listeners>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true" convertDeprecationsToExceptions="false" beStrictAboutOutputDuringTests="false" forceCoversAnnotation="true" verbose="true" bootstrap="vendor/autoload.php">
<coverage>
<include>
<directory suffix=".php">./src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>
<testsuites>
<testsuite name="unit">
<directory>./tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/integration</directory>
</testsuite>
</testsuites>
<logging/>
<listeners>
<listener class="Mockery\Adapter\Phpunit\TestListener" file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"/>
</listeners>
</phpunit>
8 changes: 4 additions & 4 deletions src/DocBlock/StandardTagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ImplementsFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\MethodFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\MixinFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateExtendsFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateCovariantFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateImplementsFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ThrowsFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
Expand Down Expand Up @@ -151,11 +151,11 @@ public static function createInstance(FqsenResolver $fqsenResolver): self
new PropertyReadFactory($typeResolver, $descriptionFactory),
new PropertyWriteFactory($typeResolver, $descriptionFactory),
new MethodFactory($typeResolver, $descriptionFactory),
new MixinFactory($typeResolver, $descriptionFactory),
new ImplementsFactory($typeResolver, $descriptionFactory),
new ExtendsFactory($typeResolver, $descriptionFactory),
new TemplateFactory($typeResolver, $descriptionFactory),
new TemplateImplementsFactory($typeResolver, $descriptionFactory),
new TemplateExtendsFactory($typeResolver, $descriptionFactory),
new TemplateCovariantFactory($typeResolver, $descriptionFactory),
new ThrowsFactory($typeResolver, $descriptionFactory),
);

Expand Down
21 changes: 14 additions & 7 deletions src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use phpDocumentor\Reflection\Types\Context as TypeContext;
use PHPStan\PhpDocParser\Lexer\Lexer;
use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\ParserException;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
Expand Down Expand Up @@ -59,13 +60,17 @@ public function __construct(PHPStanFactory ...$factories)

public function create(string $tagLine, ?TypeContext $context = null): Tag
{
$tokens = $this->tokenizeLine($tagLine . "\n");
$ast = $this->parser->parseTag($tokens);
if (property_exists($ast->value, 'description') === true) {
$ast->value->setAttribute(
'description',
rtrim($ast->value->description . $tokens->joinUntil(Lexer::TOKEN_END), "\n")
);
try {
$tokens = $this->tokenizeLine($tagLine . "\n");
$ast = $this->parser->parseTag($tokens);
if (property_exists($ast->value, 'description') === true) {
$ast->value->setAttribute(
'description',
rtrim($ast->value->description . $tokens->joinUntil(Lexer::TOKEN_END), "\n")
);
}
} catch (ParserException $e) {
return InvalidTag::create($tagLine, '')->withError($e);
}

if ($context === null) {
Expand All @@ -80,6 +85,8 @@ public function create(string $tagLine, ?TypeContext $context = null): Tag
}
} catch (RuntimeException $e) {
return InvalidTag::create((string) $ast->value, 'method')->withError($e);
} catch (ParserException $e) {
return InvalidTag::create((string) $ast->value, $ast->name)->withError($e);
}

return InvalidTag::create(
Expand Down
2 changes: 1 addition & 1 deletion src/DocBlock/Tags/Factory/MethodParameterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function format($defaultValue): string
{
$method = 'format' . ucfirst(gettype($defaultValue));
if (method_exists($this, $method)) {
return ' = ' . $this->{$method}($defaultValue);
return $this->{$method}($defaultValue);
}

return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@

use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tags\TemplateExtends;
use phpDocumentor\Reflection\DocBlock\Tags\TemplateCovariant;
use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context;
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Webmozart\Assert\Assert;

use function is_string;

/**
* @internal This class is not part of the BC promise of this library.
*/
final class TemplateExtendsFactory implements PHPStanFactory
final class TemplateCovariantFactory implements PHPStanFactory
{
private DescriptionFactory $descriptionFactory;
private TypeResolver $typeResolver;
Expand All @@ -31,21 +32,21 @@ public function __construct(TypeResolver $typeResolver, DescriptionFactory $desc

public function supports(PhpDocTagNode $node, Context $context): bool
{
return $node->value instanceof ExtendsTagValueNode && $node->name === '@template-extends';
return $node->value instanceof TemplateTagValueNode && $node->name === '@template-covariant';
}

public function create(PhpDocTagNode $node, Context $context): Tag
{
$tagValue = $node->value;
Assert::isInstanceOf($tagValue, ExtendsTagValueNode::class);
Assert::isInstanceOf($tagValue, TemplateTagValueNode::class);

$description = $tagValue->getAttribute('description');
if (is_string($description) === false) {
$description = $tagValue->description;
}

return new TemplateExtends(
$this->typeResolver->createType($tagValue->type, $context),
return new TemplateCovariant(
$this->typeResolver->createType(new IdentifierTypeNode($tagValue->name), $context),
$this->descriptionFactory->create($description, $context)
);
}
Expand Down
52 changes: 0 additions & 52 deletions src/DocBlock/Tags/Factory/TemplateImplementsFactory.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/DocBlock/Tags/MethodParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __toString(): string
'$' . $this->getName() .
(
$this->defaultValue !== self::NO_DEFAULT_VALUE ?
(new MethodParameterFactory())->format($this->defaultValue) :
' = ' . (new MethodParameterFactory())->format($this->defaultValue) :
''
);
}
Expand Down
Loading