Skip to content

Add attributes to each node #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*.php]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4
3 changes: 2 additions & 1 deletion build-cs/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"php": "^7.1 || ^8.0"
},
"require-dev": {
"consistence/coding-standard": "^3.10",
"consistence-community/coding-standard": "^3.10",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"squizlabs/php_codesniffer": "^3.5",
"slevomat/coding-standard": "^6.4.1"
}
}
1 change: 0 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<arg value="install"/>
<arg value="--working-dir"/>
<arg path="build-cs"/>
<arg value="--ignore-platform-reqs"/>
<arg value="--ansi"/>
</exec>
<exec
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<ruleset name="PHPStan PHPDoc Parser">
<config name="php_version" value="70100"/>
<rule ref="build-cs/vendor/consistence/coding-standard/Consistence/ruleset.xml">
<rule ref="build-cs/vendor/consistence-community/coding-standard/Consistence/ruleset.xml">
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.InvalidFormat"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
Expand Down
37 changes: 37 additions & 0 deletions src/Ast/BaseNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php declare(strict_types = 1);

namespace PHPStan\PhpDocParser\Ast;

abstract class BaseNode implements Node
{

/** @var array<string, mixed> */
private $attributes = [];

/**
* @param string $key
* @param mixed $value
*/
public function setAttribute(string $key, $value): void
{
$this->attributes[$key] = $value;
}

public function hasAttribute(string $key): bool
{
return array_key_exists($key, $this->attributes);
}

/**
* @return mixed|null
*/
public function getAttribute(string $key)
{
if ($this->hasAttribute($key)) {
return $this->attributes[$key];
}

return null;
}

}
4 changes: 3 additions & 1 deletion src/Ast/ConstExpr/ConstExprArrayItemNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

class ConstExprArrayItemNode implements ConstExprNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class ConstExprArrayItemNode extends BaseNode implements ConstExprNode
{

/** @var ConstExprNode|null */
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/ConstExpr/ConstExprArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

class ConstExprArrayNode implements ConstExprNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class ConstExprArrayNode extends BaseNode implements ConstExprNode
{

/** @var ConstExprArrayItemNode[] */
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/ConstExpr/ConstExprFalseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

class ConstExprFalseNode implements ConstExprNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class ConstExprFalseNode extends BaseNode implements ConstExprNode
{

public function __toString(): string
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/ConstExpr/ConstExprFloatNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

class ConstExprFloatNode implements ConstExprNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class ConstExprFloatNode extends BaseNode implements ConstExprNode
{

/** @var string */
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/ConstExpr/ConstExprIntegerNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

class ConstExprIntegerNode implements ConstExprNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class ConstExprIntegerNode extends BaseNode implements ConstExprNode
{

/** @var string */
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/ConstExpr/ConstExprNullNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

class ConstExprNullNode implements ConstExprNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class ConstExprNullNode extends BaseNode implements ConstExprNode
{

public function __toString(): string
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/ConstExpr/ConstExprStringNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

class ConstExprStringNode implements ConstExprNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class ConstExprStringNode extends BaseNode implements ConstExprNode
{

/** @var string */
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/ConstExpr/ConstExprTrueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

class ConstExprTrueNode implements ConstExprNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class ConstExprTrueNode extends BaseNode implements ConstExprNode
{

public function __toString(): string
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/ConstExpr/ConstFetchNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

class ConstFetchNode implements ConstExprNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class ConstFetchNode extends BaseNode implements ConstExprNode
{

/** @var string class name for class constants or empty string for non-class constants */
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/PhpDoc/DeprecatedTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

class DeprecatedTagValueNode implements PhpDocTagValueNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class DeprecatedTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var string (may be empty) */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/ExtendsTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;

class ExtendsTagValueNode implements PhpDocTagValueNode
class ExtendsTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var GenericTypeNode */
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/PhpDoc/GenericTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

class GenericTagValueNode implements PhpDocTagValueNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class GenericTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var string (may be empty) */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/ImplementsTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;

class ImplementsTagValueNode implements PhpDocTagValueNode
class ImplementsTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var GenericTypeNode */
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/PhpDoc/InvalidTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

class InvalidTagValueNode implements PhpDocTagValueNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class InvalidTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var string (may be empty) */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/MethodTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;

class MethodTagValueNode implements PhpDocTagValueNode
class MethodTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var bool */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/MethodTagValueParameterNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNode;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;

class MethodTagValueParameterNode implements Node
class MethodTagValueParameterNode extends BaseNode implements Node
{

/** @var TypeNode|null */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/MixinTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;

class MixinTagValueNode implements PhpDocTagValueNode
class MixinTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var TypeNode */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/ParamTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;

class ParamTagValueNode implements PhpDocTagValueNode
class ParamTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var TypeNode */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/PhpDocNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

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

class PhpDocNode implements Node
class PhpDocNode extends BaseNode implements Node
{

/** @var PhpDocChildNode[] */
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/PhpDoc/PhpDocTagNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

class PhpDocTagNode implements PhpDocChildNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class PhpDocTagNode extends BaseNode implements PhpDocChildNode
{

/** @var string */
Expand Down
4 changes: 3 additions & 1 deletion src/Ast/PhpDoc/PhpDocTextNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

class PhpDocTextNode implements PhpDocChildNode
use PHPStan\PhpDocParser\Ast\BaseNode;

class PhpDocTextNode extends BaseNode implements PhpDocChildNode
{

/** @var string */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/PropertyTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;

class PropertyTagValueNode implements PhpDocTagValueNode
class PropertyTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var TypeNode */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/ReturnTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;

class ReturnTagValueNode implements PhpDocTagValueNode
class ReturnTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var TypeNode */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/TemplateTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;

class TemplateTagValueNode implements PhpDocTagValueNode
class TemplateTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var string */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/ThrowsTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;

class ThrowsTagValueNode implements PhpDocTagValueNode
class ThrowsTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var TypeNode */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/UsesTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;

class UsesTagValueNode implements PhpDocTagValueNode
class UsesTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var GenericTypeNode */
Expand Down
3 changes: 2 additions & 1 deletion src/Ast/PhpDoc/VarTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\BaseNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;

class VarTagValueNode implements PhpDocTagValueNode
class VarTagValueNode extends BaseNode implements PhpDocTagValueNode
{

/** @var TypeNode */
Expand Down
Loading