Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3965 from neeckeloo/add-method-in-class-generator

Add removeMethod method in ClassGenerator
  • Loading branch information...
commit 3be3d07ae2a9347a17c499657743eb6b9dce4183 2 parents babe00b + 4a69836
@weierophinney weierophinney authored
View
18 library/Zend/Code/Generator/ClassGenerator.php
@@ -617,7 +617,7 @@ public function getMethods()
*/
public function getMethod($methodName)
{
- foreach ($this->getMethods() as $method) {
+ foreach ($this->methods as $method) {
if ($method->getName() == $methodName) {
return $method;
}
@@ -628,6 +628,22 @@ public function getMethod($methodName)
/**
* @param string $methodName
+ * @return ClassGenerator
+ */
+ public function removeMethod($methodName)
+ {
+ foreach ($this->methods as $key => $method) {
+ if ($method->getName() == $methodName) {
+ unset($this->methods[$key]);
+ break;
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * @param string $methodName
* @return bool
*/
public function hasMethod($methodName)
View
10 tests/ZendTest/Code/Generator/ClassGeneratorTest.php
@@ -173,6 +173,16 @@ public function testHasMethod()
$this->assertTrue($classGenerator->hasMethod('methodOne'));
}
+ public function testRemoveMethod()
+ {
+ $classGenerator = new ClassGenerator();
+ $classGenerator->addMethod('methodOne');
+ $this->assertTrue($classGenerator->hasMethod('methodOne'));
+
+ $classGenerator->removeMethod('methodOne');
+ $this->assertFalse($classGenerator->hasMethod('methodOne'));
+ }
+
/**
* @group ZF-7361
*/
Please sign in to comment.
Something went wrong with that request. Please try again.