Skip to content

Commit 4d8a95a

Browse files
committed
added PhpFile::removeNamespace()
1 parent 48c7cdf commit 4d8a95a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/PhpGenerator/PhpFile.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ public function addNamespace(string|PhpNamespace $namespace): PhpNamespace
110110
}
111111

112112

113+
/**
114+
* Removes the namespace from the file.
115+
*/
116+
public function removeNamespace(string|PhpNamespace $namespace): static
117+
{
118+
$name = $namespace instanceof PhpNamespace ? $namespace->getName() : $namespace;
119+
unset($this->namespaces[$name]);
120+
return $this;
121+
}
122+
123+
113124
/** @return PhpNamespace[] */
114125
public function getNamespaces(): array
115126
{

tests/PhpGenerator/PhpFile.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ $file->addComment('This file is auto-generated. DO NOT EDIT!');
1818
$file->addComment('Hey there, I\'m here to document things.');
1919

2020

21+
$namespace = $file->addNamespace('Deleted');
22+
$namespace->addClass('Foo');
23+
$file->removeNamespace('Deleted');
24+
2125
$namespaceFoo = $file->addNamespace('Foo');
2226

2327
$classA = $namespaceFoo->addClass('A');

0 commit comments

Comments
 (0)