From acfbb33c432dcd1226b5bbef293ea0f1ba15a129 Mon Sep 17 00:00:00 2001 From: Nicolas Eeckeloo Date: Tue, 5 Mar 2013 17:55:23 +0100 Subject: [PATCH 1/2] Add removeMethod method --- library/Zend/Code/Generator/ClassGenerator.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/library/Zend/Code/Generator/ClassGenerator.php b/library/Zend/Code/Generator/ClassGenerator.php index a0ff13aec6f..c7278cf6c19 100644 --- a/library/Zend/Code/Generator/ClassGenerator.php +++ b/library/Zend/Code/Generator/ClassGenerator.php @@ -621,7 +621,7 @@ public function getMethods() */ public function getMethod($methodName) { - foreach ($this->getMethods() as $method) { + foreach ($this->methods as $method) { if ($method->getName() == $methodName) { return $method; } @@ -630,6 +630,22 @@ public function getMethod($methodName) return false; } + /** + * @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 From 7a9a2290737d07093945bef770ddf33e8d862b5b Mon Sep 17 00:00:00 2001 From: Nicolas Eeckeloo Date: Tue, 5 Mar 2013 17:57:34 +0100 Subject: [PATCH 2/2] Add unit test --- tests/ZendTest/Code/Generator/ClassGeneratorTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/ZendTest/Code/Generator/ClassGeneratorTest.php b/tests/ZendTest/Code/Generator/ClassGeneratorTest.php index 74c2301c1b8..cfd3df4f3a1 100644 --- a/tests/ZendTest/Code/Generator/ClassGeneratorTest.php +++ b/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 */