Skip to content

Commit 2a09a7a

Browse files
committed
PhpNamespace: added removeClass() & removeFunction()
1 parent 2d57a84 commit 2a09a7a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/PhpGenerator/PhpNamespace.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ public function addEnum(string $name): ClassType
281281
}
282282

283283

284+
public function removeClass(string $name): self
285+
{
286+
unset($this->classes[strtolower($name)]);
287+
return $this;
288+
}
289+
290+
284291
public function addFunction(string $name): GlobalFunction
285292
{
286293
$lower = strtolower($name);
@@ -292,6 +299,13 @@ public function addFunction(string $name): GlobalFunction
292299
}
293300

294301

302+
public function removeFunction(string $name): self
303+
{
304+
unset($this->functions[strtolower($name)]);
305+
return $this;
306+
}
307+
308+
295309
/** @return ClassType[] */
296310
public function getClasses(): array
297311
{

tests/PhpGenerator/PhpNamespace.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ Assert::same($namespace, $interfaceB->getNamespace());
2222

2323
Assert::count(2, $namespace->getClasses());
2424
Assert::type(Nette\PhpGenerator\ClassType::class, $namespace->getClasses()['A']);
25+
$namespace->removeClass('a');
26+
Assert::count(1, $namespace->getClasses());
27+
28+
$function = $namespace->addFunction('foo');
29+
Assert::count(1, $namespace->getFunctions());
30+
Assert::same($function, $namespace->getFunctions()['foo']);
31+
$namespace->removeFunction('FOO');
32+
Assert::count(0, $namespace->getFunctions());

0 commit comments

Comments
 (0)