From 1e3d7de5168fd441a1f43f110e357a864a43e709 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 17 Oct 2024 09:50:33 +0200 Subject: [PATCH] Add method --- src/Target/Class_.php | 8 ++++++++ src/Target/ClassesThatExtendClass.php | 8 ++++++++ src/Target/ClassesThatImplementInterface.php | 8 ++++++++ src/Target/Function_.php | 8 ++++++++ src/Target/Method.php | 8 ++++++++ src/Target/Namespace_.php | 8 ++++++++ src/Target/Target.php | 5 +++++ tests/tests/Target/TargetTest.php | 6 ++++++ 8 files changed, 59 insertions(+) diff --git a/src/Target/Class_.php b/src/Target/Class_.php index 089887f64..980b93245 100644 --- a/src/Target/Class_.php +++ b/src/Target/Class_.php @@ -41,4 +41,12 @@ public function className(): string { return $this->className; } + + /** + * @return non-empty-string + */ + public function asString(): string + { + return $this->className; + } } diff --git a/src/Target/ClassesThatExtendClass.php b/src/Target/ClassesThatExtendClass.php index 5c4b0d6bd..3575160d8 100644 --- a/src/Target/ClassesThatExtendClass.php +++ b/src/Target/ClassesThatExtendClass.php @@ -41,4 +41,12 @@ public function className(): string { return $this->className; } + + /** + * @return non-empty-string + */ + public function asString(): string + { + return $this->className; + } } diff --git a/src/Target/ClassesThatImplementInterface.php b/src/Target/ClassesThatImplementInterface.php index 911fb4ca8..1d79e64f1 100644 --- a/src/Target/ClassesThatImplementInterface.php +++ b/src/Target/ClassesThatImplementInterface.php @@ -41,4 +41,12 @@ public function interfaceName(): string { return $this->interfaceName; } + + /** + * @return non-empty-string + */ + public function asString(): string + { + return $this->interfaceName; + } } diff --git a/src/Target/Function_.php b/src/Target/Function_.php index 917c3456d..1e99cde24 100644 --- a/src/Target/Function_.php +++ b/src/Target/Function_.php @@ -41,4 +41,12 @@ public function functionName(): string { return $this->functionName; } + + /** + * @return non-empty-string + */ + public function asString(): string + { + return $this->functionName; + } } diff --git a/src/Target/Method.php b/src/Target/Method.php index 388fc3071..4c649221d 100644 --- a/src/Target/Method.php +++ b/src/Target/Method.php @@ -56,4 +56,12 @@ public function methodName(): string { return $this->methodName; } + + /** + * @return non-empty-string + */ + public function asString(): string + { + return $this->className . '::' . $this->methodName; + } } diff --git a/src/Target/Namespace_.php b/src/Target/Namespace_.php index 51cd5ccf9..e2cb05278 100644 --- a/src/Target/Namespace_.php +++ b/src/Target/Namespace_.php @@ -41,4 +41,12 @@ public function namespace(): string { return $this->namespace; } + + /** + * @return non-empty-string + */ + public function asString(): string + { + return $this->namespace; + } } diff --git a/src/Target/Target.php b/src/Target/Target.php index cd4469766..2e0ce5221 100644 --- a/src/Target/Target.php +++ b/src/Target/Target.php @@ -94,4 +94,9 @@ public function isFunction(): bool { return false; } + + /** + * @return non-empty-string + */ + abstract public function asString(): string; } diff --git a/tests/tests/Target/TargetTest.php b/tests/tests/Target/TargetTest.php index 7dd4306be..f2fae9305 100644 --- a/tests/tests/Target/TargetTest.php +++ b/tests/tests/Target/TargetTest.php @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -119,5 +124,6 @@ public function testCanBeNamespace(): void $this->assertTrue($target->isNamespace()); $this->assertSame($namespace, $target->namespace()); + $this->assertSame($namespace, $target->asString()); } }