Skip to content

Commit 2dd0794

Browse files
committed
Added "Name::toUnqualified()", "Name::toUnqualifiedString()" and "Name::toUnqualifiedLowerString()" methods
1 parent 643e7d2 commit 2dd0794

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/Node/Name.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ public function toFullQualified(): FullQualifiedName
184184
return new FullQualifiedName($this->parts);
185185
}
186186

187+
/**
188+
* Convert name to unqualified name instance.
189+
*/
190+
public function toUnqualified(): self
191+
{
192+
if ($this instanceof FullQualifiedName) {
193+
return new self($this->parts);
194+
}
195+
196+
return clone $this;
197+
}
198+
187199
/**
188200
* @return non-empty-list<Identifier>
189201
*/
@@ -242,6 +254,16 @@ public function getLastPartAsString(): string
242254
* @return non-empty-string
243255
*/
244256
public function toString(): string
257+
{
258+
return $this->toUnqualifiedString();
259+
}
260+
261+
/**
262+
* Returns name as unqualified (without the initial `\\`) string.
263+
*
264+
* @return non-empty-string
265+
*/
266+
public function toUnqualifiedString(): string
245267
{
246268
return \implode(self::NAMESPACE_DELIMITER, $this->getPartsAsString());
247269
}
@@ -256,6 +278,16 @@ public function toLowerString(): string
256278
return \strtolower($this->toString());
257279
}
258280

281+
/**
282+
* Returns lowercased name as unqualified (without the initial `\\`) string.
283+
*
284+
* @return non-empty-string
285+
*/
286+
public function toUnqualifiedLowerString(): string
287+
{
288+
return \strtolower($this->toUnqualifiedString());
289+
}
290+
259291
/**
260292
* @return \Traversable<array-key, Identifier>
261293
*/

0 commit comments

Comments
 (0)