Skip to content

Commit

Permalink
added PhpFile::removeNamespace()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 25, 2024
1 parent d815ee2 commit 9afa824
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/PhpGenerator/PhpFile.php
Expand Up @@ -110,6 +110,16 @@ public function addNamespace(string|PhpNamespace $namespace): PhpNamespace
}


/**
* Removes the namespace from the file.
*/
public function removeNamespace(string|PhpNamespace $namespace): void
{
$name = $namespace instanceof PhpNamespace ? $namespace->getName() : $namespace;
unset($this->namespaces[$name]);
}


/** @return PhpNamespace[] */
public function getNamespaces(): array
{
Expand Down
4 changes: 4 additions & 0 deletions tests/PhpGenerator/PhpFile.phpt
Expand Up @@ -18,6 +18,10 @@ $file->addComment('This file is auto-generated. DO NOT EDIT!');
$file->addComment('Hey there, I\'m here to document things.');


$namespace = $file->addNamespace('Deleted');
$namespace->addClass('Foo');
$file->removeNamespace('Deleted');

$namespaceFoo = $file->addNamespace('Foo');

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

0 comments on commit 9afa824

Please sign in to comment.