-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor property rules using virtual ClassPropertyNode
- Loading branch information
1 parent
2d564e6
commit 84f1b65
Showing
9 changed files
with
204 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Node; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr; | ||
use PhpParser\Node\Identifier; | ||
use PhpParser\Node\Name; | ||
use PhpParser\Node\NullableType; | ||
use PhpParser\Node\Stmt\Class_; | ||
use PhpParser\Node\UnionType; | ||
use PhpParser\NodeAbstract; | ||
|
||
class ClassPropertyNode extends NodeAbstract implements VirtualNode | ||
{ | ||
|
||
private string $name; | ||
|
||
private int $flags; | ||
|
||
/** @var Identifier|Name|NullableType|UnionType|null */ | ||
private $type; | ||
|
||
private ?Expr $default; | ||
|
||
private ?string $phpDoc; | ||
|
||
/** | ||
* @param int $flags | ||
* @param Identifier|Name|NullableType|UnionType|null $type | ||
* @param string $name | ||
* @param Expr|null $default | ||
*/ | ||
public function __construct( | ||
string $name, | ||
int $flags, | ||
$type, | ||
?Expr $default, | ||
?string $phpDoc, | ||
Node $originalNode | ||
) | ||
{ | ||
parent::__construct($originalNode->getAttributes()); | ||
$this->name = $name; | ||
$this->flags = $flags; | ||
$this->type = $type; | ||
$this->default = $default; | ||
$this->phpDoc = $phpDoc; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getFlags(): int | ||
{ | ||
return $this->flags; | ||
} | ||
|
||
public function getDefault(): ?Expr | ||
{ | ||
return $this->default; | ||
} | ||
|
||
public function getPhpDoc(): ?string | ||
{ | ||
return $this->phpDoc; | ||
} | ||
|
||
public function isPublic(): bool | ||
{ | ||
return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0 | ||
|| ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0; | ||
} | ||
|
||
public function isProtected(): bool | ||
{ | ||
return (bool) ($this->flags & Class_::MODIFIER_PROTECTED); | ||
} | ||
|
||
public function isPrivate(): bool | ||
{ | ||
return (bool) ($this->flags & Class_::MODIFIER_PRIVATE); | ||
} | ||
|
||
public function isStatic(): bool | ||
{ | ||
return (bool) ($this->flags & Class_::MODIFIER_STATIC); | ||
} | ||
|
||
/** | ||
* @return Identifier|Name|NullableType|UnionType|null | ||
*/ | ||
public function getNativeType() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return 'PHPStan_Node_ClassPropertyNode'; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getSubNodeNames(): array | ||
{ | ||
return []; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.