Skip to content

Commit

Permalink
fix last token print
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 19, 2021
1 parent 72ea310 commit 02ced67
Show file tree
Hide file tree
Showing 34 changed files with 122 additions and 183 deletions.
73 changes: 4 additions & 69 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@
"nette/robot-loader": "^3.4",
"nette/utils": "^3.2",
"nikic/php-parser": "^4.10.4",
<<<<<<< HEAD
"phpstan/phpdoc-parser": "0.4.12",
=======
"phpstan/phpdoc-parser": "dev-tv-add-attributes as 0.4.12",
>>>>>>> f8f4ccf9ef... fixup! [scoper] skip polyfill functions to make them work
"phpstan/phpstan": "^0.12.81",
"phpstan/phpdoc-parser": "0.5 as 0.4.12",
"phpstan/phpstan": "^0.12.82",
"phpstan/phpstan-phpunit": "^0.12.18",
"rector/rector-symfony": "dev-main",
"rector/rector-nette": "dev-main",
Expand All @@ -56,19 +52,6 @@
"symfony/http-kernel": "^4.4.8|^5.1",
"symfony/process": "^4.4.8|^5.1",
"symfony/uid": "^4.4.8|^5.1",
<<<<<<< HEAD
"symplify/astral": "^9.2",
"symplify/autowire-array-parameter": "^9.2",
"symplify/console-color-diff": "^9.2",
"symplify/package-builder": "^9.2",
"symplify/rule-doc-generator-contracts": "^9.2",
"symplify/set-config-resolver": "^9.2",
"symplify/simple-php-doc-parser": "^9.2",
"symplify/skipper": "^9.2",
"symplify/smart-file-system": "^9.2",
"symplify/symfony-php-config": "^9.2",
=======
<<<<<<< HEAD
"symplify/astral": "^9.2.11",
"symplify/autowire-array-parameter": "^9.2.11",
"symplify/console-color-diff": "^9.2.11",
Expand All @@ -79,19 +62,6 @@
"symplify/skipper": "^9.2.11",
"symplify/smart-file-system": "^9.2.11",
"symplify/symfony-php-config": "^9.2.11",
=======
"symplify/astral": "^9.2.4",
"symplify/autowire-array-parameter": "^9.2.4",
"symplify/console-color-diff": "^9.2.4",
"symplify/package-builder": "^9.2.4",
"symplify/rule-doc-generator": "^9.2.4",
"symplify/set-config-resolver": "^9.2.4",
"symplify/simple-php-doc-parser": "dev-main",
"symplify/skipper": "^9.2.4",
"symplify/smart-file-system": "^9.2.4",
"symplify/symfony-php-config": "^9.2.4",
>>>>>>> f6ec46d106... remove attribute aware return tag
>>>>>>> 2f5596fa17... remove AttributeAware*
"webmozart/assert": "^1.10"
},
"require-dev": {
Expand Down Expand Up @@ -120,36 +90,7 @@
"Rector\\": ["packages", "rules"],
"Rector\\Core\\": "src",
"Rector\\Compiler\\": "utils/compiler/src"
},
"files": [
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/PhpDocNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/PhpDocTagNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/PropertyTagValueNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/DeprecatedTagValueNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/ExtendsTagValueNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/ThrowsTagValueNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/InvalidTagValueNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/MethodTagValueNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/MethodTagValueParameterNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/GenericTagValueNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/ReturnTagValueNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/TemplateTagValueNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/PhpDocTextNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/ParamTagValueNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/VarTagValueNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/ArrayTypeNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/ThisTypeNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/IdentifierTypeNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/UnionTypeNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/ConstTypeNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/NullableTypeNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/IntersectionTypeNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeItemNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/GenericTypeNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/CallableTypeNode.php",
"vendor/phpstan/phpdoc-parser/src/Ast/Type/CallableTypeParameterNode.php"
]
}
},
"autoload-dev": {
"psr-4": {
Expand Down Expand Up @@ -211,11 +152,5 @@
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{
"type": "git",
"url": "https://github.com/TomasVotruba/phpdoc-parser.git"
}
]
"prefer-stable": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode;
use Symplify\SimplePhpDocParser\ValueObject\Ast\PhpDoc\SimplePhpDocNode;

final class AttributeAwarePhpDocNode extends SimplePhpDocNode
{
use NodeAttributes;

/**
* @var array<PhpDocChildNode&BaseNode>
* @var array<PhpDocChildNode>
*/
public $children = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;

final class DataProviderTagValueNode implements PhpDocTagValueNode
{
use NodeAttributes;

/**
* @var string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
namespace Rector\AttributeAwarePhpDoc\Ast\Type;

use Nette\Utils\Strings;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;

final class AttributeAwareCallableTypeNode extends CallableTypeNode
{
use NodeAttributes;

public function __toString(): string
{
// keep original (Psalm?) format, see https://github.com/rectorphp/rector/issues/2841
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public function isMatch(Node $node): bool

/**
* @param ParamTagValueNode $node
* @return AttributeAwareParamTagValueNode
*/
public function create(Node $node, string $docContent): AttributeAwareParamTagValueNode
public function create(Node $node, string $docContent): Node
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ public function isMatch(Node $node): bool

/**
* @param PhpDocNode $node
* @return AttributeAwarePhpDocNode
*/
public function create(Node $node, string $docContent)
public function create(Node $node, string $docContent): Node
{
$this->phpDocNodeTraverser->traverseWithCallable($node, $docContent, function (Node $node) use (
$docContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public function isMatch(Node $node): bool

/**
* @param ArrayShapeItemNode $node
* @return AttributeAwareArrayShapeItemNode
*/
public function create(Node $node, string $docContent): AttributeAwareArrayShapeItemNode
public function create(Node $node, string $docContent): Node
{
$node->valueType = $this->attributeAwareNodeFactory->createFromNode($node->valueType, $docContent);
return new AttributeAwareArrayShapeItemNode($node->keyName, $node->optional, $node->valueType, $docContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public function isMatch(Node $node): bool

/**
* @param ArrayTypeNode $node
* @return AttributeAwareArrayTypeNode
*/
public function create(Node $node, string $docContent): AttributeAwareArrayTypeNode
public function create(Node $node, string $docContent): Node
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public function isMatch(Node $node): bool

/**
* @param CallableTypeNode $node
* @return AttributeAwareCallableTypeNode
*/
public function create(Node $node, string $docContent): AttributeAwareCallableTypeNode
public function create(Node $node, string $docContent): Node
{
$identifier = $this->attributeAwareNodeFactory->createFromNode($node->identifier, $docContent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function isMatch(Node $node): bool
/**
* @param IntersectionTypeNode $node
*/
public function create(Node $node, string $docContent): AttributeAwareIntersectionTypeNode
public function create(Node $node, string $docContent): Node
{
foreach ($node->types as $key => $intersectionedType) {
$node->types[$key] = $this->attributeAwareNodeFactory->createFromNode($intersectionedType, $docContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

namespace Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Node;

interface AttributeNodeAwareFactoryInterface
{
public function isMatch(Node $node): bool;

/**
* @return BaseNode
* @template T of Node
* @param T $node
* @return T
*/
public function create(Node $node, string $docContent);
public function create(Node $node, string $docContent): Node;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

namespace Rector\BetterPhpDocParser\Attributes\Ast;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareArrayShapeItemNode;
Expand Down Expand Up @@ -38,17 +34,26 @@ final class AttributeAwareNodeFactory
*/
public function __construct(array $attributeAwareNodeFactories, PhpDocNodeTraverser $phpDocNodeTraverser)
{
foreach ($attributeAwareNodeFactories as $attributeAwareNodeFactory) {
// prevents cyclic dependency
if ($attributeAwareNodeFactory instanceof AttributeAwareNodeFactoryAwareInterface) {
$attributeAwareNodeFactory->setAttributeAwareNodeFactory($this);
}
}

$this->attributeAwareNodeFactories = $attributeAwareNodeFactories;
$this->phpDocNodeTraverser = $phpDocNodeTraverser;
}

/**
* @return PhpDocNode|PhpDocChildNode|PhpDocTagValueNode|BaseNode
* @template T of \PHPStan\PhpDocParser\Ast\Node
* @param T $node
* @return T
*/
public function createFromNode(Node $node, string $docContent): BaseNode
public function createFromNode(Node $node, string $docContent): Node
{
$node = $this->phpDocNodeTraverser->traverseWithCallable($node, $docContent, function (
$node,
Node $node,
string $docContent
) {
if ($node instanceof UnionTypeNode && ! $node instanceof AttributeAwareUnionTypeNode) {
Expand All @@ -71,11 +76,6 @@ public function createFromNode(Node $node, string $docContent): BaseNode
continue;
}

// prevents cyclic dependency
if ($attributeAwareNodeFactory instanceof AttributeAwareNodeFactoryAwareInterface) {
$attributeAwareNodeFactory->setAttributeAwareNodeFactory($this);
}

return $attributeAwareNodeFactory->create($node, $docContent);
}

Expand Down
15 changes: 10 additions & 5 deletions packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\BetterPhpDocParser\PhpDocInfo;

use PhpParser\Node;
use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Node as PhpDocNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
Expand Down Expand Up @@ -175,7 +174,7 @@ public function getVarTagValueNode(): ?VarTagValueNode
}

/**
* @return array<PhpDocTagNode&BaseNode>
* @return array<PhpDocTagNode>
*/
public function getTagsByName(string $name): array
{
Expand All @@ -193,8 +192,8 @@ public function getTagsByName(string $name): array

public function getParamType(string $name): Type
{
$attributeAwareParamTagValueNode = $this->getParamTagValueByName($name);
return $this->getTypeOrMixed($attributeAwareParamTagValueNode);
$paramTagValueByName = $this->getParamTagValueByName($name);
return $this->getTypeOrMixed($paramTagValueByName);
}

/**
Expand Down Expand Up @@ -300,7 +299,7 @@ public function getByType(string $type): ?PhpDocNode
/**
* @template T of \PHPStan\PhpDocParser\Ast\Node
* @param class-string<T> $type
* @return T[]
* @return array<T>
*/
public function findAllByType(string $type): array
{
Expand Down Expand Up @@ -330,9 +329,14 @@ public function findAllByType(string $type): array
$foundTagsValueNodes[] = $phpDocChildNode->value;
}

/** @var \PHPStan\PhpDocParser\Ast\Node[] $foundTagsValueNodes */
return $foundTagsValueNodes;
}

/**
* @template T of \PHPStan\PhpDocParser\Ast\Node
* @param class-string<T> $type
*/
public function removeByType(string $type): void
{
$this->ensureTypeIsTagValueNode($type, __METHOD__);
Expand Down Expand Up @@ -478,6 +482,7 @@ private function getTypeOrMixed(?PhpDocTagValueNode $phpDocTagValueNode): Type

private function ensureTypeIsTagValueNode(string $type, string $location): void
{
/** @var array<class-string> $desiredTypes */
$desiredTypes = array_merge([
PhpDocTagValueNode::class,
PhpDocTagNode::class,
Expand Down
2 changes: 0 additions & 2 deletions packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PhpParser\Comment\Doc;
use PhpParser\Node;
use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Lexer\Lexer;
use PHPStan\PhpDocParser\Parser\ParserException;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
Expand Down Expand Up @@ -169,7 +168,6 @@ private function setPositionOfLastToken(AttributeAwarePhpDocNode $attributeAware
}

$phpDocChildNodes = $attributeAwarePhpDocNode->children;
/** @var BaseNode $lastChildNode */
$lastChildNode = array_pop($phpDocChildNodes);

/** @var StartAndEnd $startAndEnd */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ public function decorateNodeWithInlineVarType(

$fullyQualifiedIdentifierTypeNode = new FullyQualifiedIdentifierTypeNode($typeWithClassName->getClassName());

$attributeAwareVarTagValueNode = new VarTagValueNode(
$fullyQualifiedIdentifierTypeNode,
'$' . $variableName,
''
);
$phpDocInfo->addTagValueNode($attributeAwareVarTagValueNode);
$varTagValueNode = new VarTagValueNode($fullyQualifiedIdentifierTypeNode, '$' . $variableName, '');
$phpDocInfo->addTagValueNode($varTagValueNode);
}

public function decorateNodeWithType(Node $node, Type $staticType): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ private function parseChildAndStoreItsPositions(TokenIterator $tokenIterator): N
$docContent = $this->annotationContentResolver->resolveFromTokenIterator($originalTokenIterator);

$tokenStart = $this->getTokenIteratorIndex($tokenIterator);

/** @var PhpDocNode $phpDocNode */
$phpDocNode = $this->privatesCaller->callPrivateMethod($this, 'parseChild', [$tokenIterator]);

$tokenEnd = $this->resolveTokenEnd($tokenIterator);
Expand Down
Loading

0 comments on commit 02ced67

Please sign in to comment.