-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RequireExtends and RequireImplements attributes
- Loading branch information
1 parent
1028781
commit 1eaf5e0
Showing
5 changed files
with
109 additions
and
2 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,31 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\NodeVisitor; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Attribute; | ||
use PhpParser\Node\AttributeGroup; | ||
use PhpParser\Node\Name\FullyQualified; | ||
use PhpStaticAnalysis\Attributes\RequireExtends; | ||
|
||
class RequireExtendsAttributeNodeVisitorTest extends AttributeNodeVisitorTestBase | ||
{ | ||
public function testAddsRequireExtendsPHPDoc(): void | ||
{ | ||
$node = new Node\Stmt\Trait_('Test'); | ||
$this->addRequireExtendsAttributeToNode($node); | ||
$this->nodeVisitor->enterNode($node); | ||
$docText = $this->getDocText($node); | ||
$this->assertEquals("/**\n * @require-extends RequireClass\n */", $docText); | ||
} | ||
|
||
private function addRequireExtendsAttributeToNode(Node\Stmt\Trait_ $node): void | ||
{ | ||
$args = [ | ||
new Node\Arg(new Node\Scalar\String_('RequireClass')) | ||
]; | ||
$attributeName = new FullyQualified(RequireExtends::class); | ||
$attribute = new Attribute($attributeName, $args); | ||
$node->attrGroups = array_merge($node->attrGroups, [new AttributeGroup([$attribute])]); | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\NodeVisitor; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Attribute; | ||
use PhpParser\Node\AttributeGroup; | ||
use PhpParser\Node\Name\FullyQualified; | ||
use PhpStaticAnalysis\Attributes\RequireImplements; | ||
|
||
class RequireImplementsAttributeNodeVisitorTest extends AttributeNodeVisitorTestBase | ||
{ | ||
public function testAddsRequireImplementsPHPDoc(): void | ||
{ | ||
$node = new Node\Stmt\Trait_('Test'); | ||
$this->addRequireImplementsAttributesToNode($node); | ||
$this->nodeVisitor->enterNode($node); | ||
$docText = $this->getDocText($node); | ||
$this->assertEquals("/**\n * @require-implements RequireInterface\n */", $docText); | ||
} | ||
|
||
public function testAddsSeveralRequireImplementsPHPDocs(): void | ||
{ | ||
$node = new Node\Stmt\Trait_('Test'); | ||
$this->addRequireImplementsAttributesToNode($node, 2); | ||
$this->nodeVisitor->enterNode($node); | ||
$docText = $this->getDocText($node); | ||
$this->assertEquals("/**\n * @require-implements RequireInterface\n * @require-implements RequireInterface\n */", $docText); | ||
} | ||
|
||
public function testAddsMultipleRequireImplementsPHPDocs(): void | ||
{ | ||
$node = new Node\Stmt\Trait_('Test'); | ||
$this->addRequireImplementsAttributesToNode($node); | ||
$this->addRequireImplementsAttributesToNode($node); | ||
$this->nodeVisitor->enterNode($node); | ||
$docText = $this->getDocText($node); | ||
$this->assertEquals("/**\n * @require-implements RequireInterface\n * @require-implements RequireInterface\n */", $docText); | ||
} | ||
|
||
private function addRequireImplementsAttributesToNode(Node\Stmt\Trait_ $node, int $num = 1): void | ||
{ | ||
$value = new Node\Scalar\String_('RequireInterface'); | ||
$args = []; | ||
for ($i = 0; $i < $num; $i++) { | ||
$args[] = new Node\Arg($value); | ||
} | ||
$attributeName = new FullyQualified(RequireImplements::class); | ||
$attribute = new Attribute($attributeName, $args); | ||
$node->attrGroups = array_merge($node->attrGroups, [new AttributeGroup([$attribute])]); | ||
} | ||
} |
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