Skip to content

Commit fc06264

Browse files
Add method
1 parent d6e6ecd commit fc06264

File tree

8 files changed

+59
-0
lines changed

8 files changed

+59
-0
lines changed

src/Target/Class_.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ public function className(): string
4141
{
4242
return $this->className;
4343
}
44+
45+
/**
46+
* @return non-empty-string
47+
*/
48+
public function asString(): string
49+
{
50+
return $this->className;
51+
}
4452
}

src/Target/ClassesThatExtendClass.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ public function className(): string
4141
{
4242
return $this->className;
4343
}
44+
45+
/**
46+
* @return non-empty-string
47+
*/
48+
public function asString(): string
49+
{
50+
return $this->className;
51+
}
4452
}

src/Target/ClassesThatImplementInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ public function interfaceName(): string
4141
{
4242
return $this->interfaceName;
4343
}
44+
45+
/**
46+
* @return non-empty-string
47+
*/
48+
public function asString(): string
49+
{
50+
return $this->interfaceName;
51+
}
4452
}

src/Target/Function_.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ public function functionName(): string
4141
{
4242
return $this->functionName;
4343
}
44+
45+
/**
46+
* @return non-empty-string
47+
*/
48+
public function asString(): string
49+
{
50+
return $this->functionName;
51+
}
4452
}

src/Target/Method.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,12 @@ public function methodName(): string
5656
{
5757
return $this->methodName;
5858
}
59+
60+
/**
61+
* @return non-empty-string
62+
*/
63+
public function asString(): string
64+
{
65+
return $this->className . '::' . $this->methodName;
66+
}
5967
}

src/Target/Namespace_.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ public function namespace(): string
4141
{
4242
return $this->namespace;
4343
}
44+
45+
/**
46+
* @return non-empty-string
47+
*/
48+
public function asString(): string
49+
{
50+
return $this->namespace;
51+
}
4452
}

src/Target/Target.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,9 @@ public function isFunction(): bool
9494
{
9595
return false;
9696
}
97+
98+
/**
99+
* @return non-empty-string
100+
*/
101+
abstract public function asString(): string;
97102
}

tests/tests/Target/TargetTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function testCanBeClass(): void
3737
$this->assertFalse($target->isNamespace());
3838

3939
$this->assertSame($className, $target->className());
40+
$this->assertSame($className, $target->asString());
4041
}
4142

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

5556
$this->assertSame($className, $target->className());
57+
$this->assertSame($className, $target->asString());
5658
}
5759

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

7173
$this->assertSame($interfaceName, $target->interfaceName());
74+
$this->assertSame($interfaceName, $target->asString());
7275
}
7376

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

8790
$this->assertSame($functionName, $target->functionName());
91+
$this->assertSame($functionName, $target->asString());
8892
}
8993

9094
public function testCanBeMethod(): void
@@ -103,6 +107,7 @@ public function testCanBeMethod(): void
103107

104108
$this->assertSame($className, $target->className());
105109
$this->assertSame($methodName, $target->methodName());
110+
$this->assertSame($className . '::' . $methodName, $target->asString());
106111
}
107112

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

121126
$this->assertSame($namespace, $target->namespace());
127+
$this->assertSame($namespace, $target->asString());
122128
}
123129
}

0 commit comments

Comments
 (0)