Skip to content
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

Allow nodes to have custom attributes #65

Merged
merged 1 commit into from
Mar 18, 2021
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
4 changes: 4 additions & 0 deletions src/Ast/ConstExpr/ConstExprArrayItemNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class ConstExprArrayItemNode implements ConstExprNode
{

use NodeAttributes;

/** @var ConstExprNode|null */
public $key;

Expand Down
4 changes: 4 additions & 0 deletions src/Ast/ConstExpr/ConstExprArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class ConstExprArrayNode implements ConstExprNode
{

use NodeAttributes;

/** @var ConstExprArrayItemNode[] */
public $items;

Expand Down
4 changes: 4 additions & 0 deletions src/Ast/ConstExpr/ConstExprFalseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class ConstExprFalseNode implements ConstExprNode
{

use NodeAttributes;

public function __toString(): string
{
return 'false';
Expand Down
4 changes: 4 additions & 0 deletions src/Ast/ConstExpr/ConstExprFloatNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class ConstExprFloatNode implements ConstExprNode
{

use NodeAttributes;

/** @var string */
public $value;

Expand Down
4 changes: 4 additions & 0 deletions src/Ast/ConstExpr/ConstExprIntegerNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class ConstExprIntegerNode implements ConstExprNode
{

use NodeAttributes;

/** @var string */
public $value;

Expand Down
4 changes: 4 additions & 0 deletions src/Ast/ConstExpr/ConstExprNullNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class ConstExprNullNode implements ConstExprNode
{

use NodeAttributes;

public function __toString(): string
{
return 'null';
Expand Down
4 changes: 4 additions & 0 deletions src/Ast/ConstExpr/ConstExprStringNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class ConstExprStringNode implements ConstExprNode
{

use NodeAttributes;

/** @var string */
public $value;

Expand Down
4 changes: 4 additions & 0 deletions src/Ast/ConstExpr/ConstExprTrueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class ConstExprTrueNode implements ConstExprNode
{

use NodeAttributes;

public function __toString(): string
{
return 'true';
Expand Down
4 changes: 4 additions & 0 deletions src/Ast/ConstExpr/ConstFetchNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\ConstExpr;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class ConstFetchNode implements ConstExprNode
{

use NodeAttributes;

/** @var string class name for class constants or empty string for non-class constants */
public $className;

Expand Down
14 changes: 14 additions & 0 deletions src/Ast/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,18 @@ interface Node

public function __toString(): string;

/**
* @param string $key
* @param mixed $value
*/
public function setAttribute(string $key, $value): void;

public function hasAttribute(string $key): bool;

/**
* @param string $key
* @return mixed
*/
public function getAttribute(string $key);

}
38 changes: 38 additions & 0 deletions src/Ast/NodeAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(strict_types = 1);

namespace PHPStan\PhpDocParser\Ast;

trait NodeAttributes
{

/** @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);
}

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

return null;
}

}
4 changes: 4 additions & 0 deletions src/Ast/PhpDoc/DeprecatedTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class DeprecatedTagValueNode implements PhpDocTagValueNode
{

use NodeAttributes;

/** @var string (may be empty) */
public $description;

Expand Down
3 changes: 3 additions & 0 deletions src/Ast/PhpDoc/ExtendsTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

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

class ExtendsTagValueNode implements PhpDocTagValueNode
{

use NodeAttributes;

/** @var GenericTypeNode */
public $type;

Expand Down
4 changes: 4 additions & 0 deletions src/Ast/PhpDoc/GenericTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class GenericTagValueNode implements PhpDocTagValueNode
{

use NodeAttributes;

/** @var string (may be empty) */
public $value;

Expand Down
3 changes: 3 additions & 0 deletions src/Ast/PhpDoc/ImplementsTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

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

class ImplementsTagValueNode implements PhpDocTagValueNode
{

use NodeAttributes;

/** @var GenericTypeNode */
public $type;

Expand Down
4 changes: 4 additions & 0 deletions src/Ast/PhpDoc/InvalidTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class InvalidTagValueNode implements PhpDocTagValueNode
{

use NodeAttributes;

/** @var string (may be empty) */
public $value;

Expand Down
3 changes: 3 additions & 0 deletions src/Ast/PhpDoc/MethodTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

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

class MethodTagValueNode implements PhpDocTagValueNode
{

use NodeAttributes;

/** @var bool */
public $isStatic;

Expand Down
3 changes: 3 additions & 0 deletions src/Ast/PhpDoc/MethodTagValueParameterNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

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

class MethodTagValueParameterNode implements Node
{

use NodeAttributes;

/** @var TypeNode|null */
public $type;

Expand Down
3 changes: 3 additions & 0 deletions src/Ast/PhpDoc/MixinTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

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

class MixinTagValueNode implements PhpDocTagValueNode
{

use NodeAttributes;

/** @var TypeNode */
public $type;

Expand Down
3 changes: 3 additions & 0 deletions src/Ast/PhpDoc/ParamTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

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

class ParamTagValueNode implements PhpDocTagValueNode
{

use NodeAttributes;

/** @var TypeNode */
public $type;

Expand Down
3 changes: 3 additions & 0 deletions src/Ast/PhpDoc/PhpDocNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\NodeAttributes;

class PhpDocNode implements Node
{

use NodeAttributes;

/** @var PhpDocChildNode[] */
public $children;

Expand Down
4 changes: 4 additions & 0 deletions src/Ast/PhpDoc/PhpDocTagNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class PhpDocTagNode implements PhpDocChildNode
{

use NodeAttributes;

/** @var string */
public $name;

Expand Down
4 changes: 4 additions & 0 deletions src/Ast/PhpDoc/PhpDocTextNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

use PHPStan\PhpDocParser\Ast\NodeAttributes;

class PhpDocTextNode implements PhpDocChildNode
{

use NodeAttributes;

/** @var string */
public $text;

Expand Down
3 changes: 3 additions & 0 deletions src/Ast/PhpDoc/PropertyTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

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

class PropertyTagValueNode implements PhpDocTagValueNode
{

use NodeAttributes;

/** @var TypeNode */
public $type;

Expand Down
3 changes: 3 additions & 0 deletions src/Ast/PhpDoc/ReturnTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace PHPStan\PhpDocParser\Ast\PhpDoc;

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

class ReturnTagValueNode implements PhpDocTagValueNode
{

use NodeAttributes;

/** @var TypeNode */
public $type;

Expand Down
Loading