Skip to content

Commit d204f75

Browse files
committed
Ignore the modification of the method if it is abstract
1 parent c587879 commit d204f75

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Compiler/Visitor/ContractsApplicatorVisitor.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Serafim\Contracts\Compiler\Visitor;
1313

1414
use PhpParser\Node;
15+
use PhpParser\Node\Stmt\Class_;
1516
use PhpParser\NodeTraverser;
1617
use PhpParser\NodeVisitorAbstract;
1718
use Serafim\Contracts\Attribute\Invariant;
@@ -54,7 +55,7 @@ public function __construct(
5455
*/
5556
public function enterNode(Node $node): ?int
5657
{
57-
if ($node instanceof Node\Stmt\Class_) {
58+
if ($node instanceof Class_) {
5859
$this->class = $node->name->toString();
5960
}
6061

@@ -71,12 +72,16 @@ public function enterNode(Node $node): ?int
7172
public function leaveNode(Node $node): void
7273
{
7374
// Clear all invariants
74-
if ($node instanceof Node\Stmt\Class_) {
75+
if ($node instanceof Class_) {
7576
$this->invariants = [];
7677
$this->class = null;
7778
}
7879

7980
if ($node instanceof Node\Stmt\ClassMethod) {
81+
if (($node->flags & Class_::MODIFIER_ABSTRACT) === Class_::MODIFIER_ABSTRACT) {
82+
return;
83+
}
84+
8085
$this->injector->inject($this->file, $node, $this->invariants);
8186
}
8287
}

0 commit comments

Comments
 (0)