Skip to content

Commit

Permalink
Implement Class_::hasParent()
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Oct 9, 2024
1 parent 99b1561 commit 0a140e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/StaticAnalysis/Value/Class_.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public function endLine(): int
return $this->endLine;
}

public function hasParent(): bool
{
return $this->parentClass !== null;
}

/**
* @return ?non-empty-string
*/
Expand Down
6 changes: 5 additions & 1 deletion tests/tests/StaticAnalysis/Value/ClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ public function testMayHaveParentClass(): void
{
$parentClass = 'example\ParentClass';

$this->assertSame($parentClass, $this->class(parentClass: $parentClass)->parentClass());
$class = $this->class(parentClass: $parentClass);

$this->assertTrue($class->hasParent());
$this->assertSame($parentClass, $class->parentClass());
}

public function testMayNotHaveParentClass(): void
{
$this->assertFalse($this->class()->hasParent());
$this->assertNull($this->class()->parentClass());
}

Expand Down

0 comments on commit 0a140e3

Please sign in to comment.