Skip to content

Commit

Permalink
Add method
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Oct 31, 2024
1 parent 67637df commit 1e3d7de
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Target/Class_.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ public function className(): string
{
return $this->className;
}

/**
* @return non-empty-string
*/
public function asString(): string
{
return $this->className;
}
}
8 changes: 8 additions & 0 deletions src/Target/ClassesThatExtendClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ public function className(): string
{
return $this->className;
}

/**
* @return non-empty-string
*/
public function asString(): string
{
return $this->className;
}
}
8 changes: 8 additions & 0 deletions src/Target/ClassesThatImplementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ public function interfaceName(): string
{
return $this->interfaceName;
}

/**
* @return non-empty-string
*/
public function asString(): string
{
return $this->interfaceName;
}
}
8 changes: 8 additions & 0 deletions src/Target/Function_.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ public function functionName(): string
{
return $this->functionName;
}

/**
* @return non-empty-string
*/
public function asString(): string
{
return $this->functionName;
}
}
8 changes: 8 additions & 0 deletions src/Target/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,12 @@ public function methodName(): string
{
return $this->methodName;
}

/**
* @return non-empty-string
*/
public function asString(): string
{
return $this->className . '::' . $this->methodName;
}
}
8 changes: 8 additions & 0 deletions src/Target/Namespace_.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ public function namespace(): string
{
return $this->namespace;
}

/**
* @return non-empty-string
*/
public function asString(): string
{
return $this->namespace;
}
}
5 changes: 5 additions & 0 deletions src/Target/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,9 @@ public function isFunction(): bool
{
return false;
}

/**
* @return non-empty-string
*/
abstract public function asString(): string;
}
6 changes: 6 additions & 0 deletions tests/tests/Target/TargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function testCanBeClass(): void
$this->assertFalse($target->isNamespace());

$this->assertSame($className, $target->className());
$this->assertSame($className, $target->asString());
}

public function testCanBeClassesThatExtendClass(): void
Expand All @@ -53,6 +54,7 @@ public function testCanBeClassesThatExtendClass(): void
$this->assertFalse($target->isNamespace());

$this->assertSame($className, $target->className());
$this->assertSame($className, $target->asString());
}

public function testCanBeClassesThatImplementInterface(): void
Expand All @@ -69,6 +71,7 @@ public function testCanBeClassesThatImplementInterface(): void
$this->assertFalse($target->isNamespace());

$this->assertSame($interfaceName, $target->interfaceName());
$this->assertSame($interfaceName, $target->asString());
}

public function testCanBeFunction(): void
Expand All @@ -85,6 +88,7 @@ public function testCanBeFunction(): void
$this->assertFalse($target->isNamespace());

$this->assertSame($functionName, $target->functionName());
$this->assertSame($functionName, $target->asString());
}

public function testCanBeMethod(): void
Expand All @@ -103,6 +107,7 @@ public function testCanBeMethod(): void

$this->assertSame($className, $target->className());
$this->assertSame($methodName, $target->methodName());
$this->assertSame($className . '::' . $methodName, $target->asString());
}

public function testCanBeNamespace(): void
Expand All @@ -119,5 +124,6 @@ public function testCanBeNamespace(): void
$this->assertTrue($target->isNamespace());

$this->assertSame($namespace, $target->namespace());
$this->assertSame($namespace, $target->asString());
}
}

0 comments on commit 1e3d7de

Please sign in to comment.