Skip to content

Commit 8fe7e69

Browse files
committed
ClassType: added removeImplement() & removeTrait() [Closes #53]
1 parent ea96bdc commit 8fe7e69

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,17 @@ public function addImplement(string $name): self
268268
}
269269

270270

271+
/** @return static */
272+
public function removeImplement(string $name): self
273+
{
274+
$key = array_search($name, $this->implements, true);
275+
if ($key !== false) {
276+
unset($this->implements[$key]);
277+
}
278+
return $this;
279+
}
280+
281+
271282
/**
272283
* @param string[] $names
273284
* @return static
@@ -303,6 +314,14 @@ public function addTrait(string $name, array $resolutions = []): self
303314
}
304315

305316

317+
/** @return static */
318+
public function removeTrait(string $name): self
319+
{
320+
unset($this->traits[$name]);
321+
return $this;
322+
}
323+
324+
306325
/**
307326
* @param Method|Property|Constant $member
308327
* @return static

tests/PhpGenerator/ClassType.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ $method->addParameter('res', null)
123123
->setReference(true)
124124
->setType(Type::ARRAY);
125125

126+
127+
$class->addTrait('foo');
128+
$class->removeTrait('foo');
129+
130+
$class->addImplement('foo');
131+
$class->removeImplement('foo');
132+
133+
126134
sameFile(__DIR__ . '/expected/ClassType.expect', (string) $class);
127135

128136

0 commit comments

Comments
 (0)