Skip to content

Commit 6a4610e

Browse files
committed
Merge pull request #22 from ksimka/patch-1
Fix getMethod
2 parents 4bbdcb4 + 9464cf0 commit 6a4610e

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/phpDocumentor/Reflection/InterfaceReflector.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function parseSubElements()
4848
}
4949
break;
5050
case 'PHPParser_Node_Stmt_ClassMethod':
51-
$this->methods[] = new ClassReflector\MethodReflector(
51+
$this->methods[strtolower($stmt->name)] = new ClassReflector\MethodReflector(
5252
$stmt,
5353
$this->context
5454
);
@@ -107,10 +107,12 @@ public function getMethods()
107107

108108
/**
109109
* @param string $name the method name
110-
* @return ClassReflector\MethodReflector
110+
* @return ClassReflector\MethodReflector|null
111111
*/
112112
public function getMethod($name)
113113
{
114-
return $this->methods[$name];
114+
$name = strtolower($name);
115+
116+
return isset($this->methods[$name]) ? $this->methods[$name] : null;
115117
}
116118
}

tests/unit/phpDocumentor/Reflection/ClassReflectorTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,33 @@ public function testGetInterfaces()
149149

150150
$this->assertEquals(array('\dummy'), $class_reflector->getInterfaces());
151151
}
152+
153+
/**
154+
* Tests the getMethod method
155+
*
156+
* @covers \phpDocumentor\Reflection\ClassReflector::getMethod
157+
*
158+
* @return void
159+
*/
160+
public function testGetMethod()
161+
{
162+
$node = new NodeStmtMock();
163+
$node->stmts = array(new \PHPParser_Node_Stmt_ClassMethod('someMethod'));
164+
$class_reflector = new ClassReflectorMock(
165+
$node,
166+
new Context()
167+
);
168+
169+
// Before parseSubElements
170+
$this->assertNull($class_reflector->getMethod('someMethod'));
171+
172+
$class_reflector->parseSubElements();
173+
174+
// After parseSubElements
175+
$this->assertInstanceOf(
176+
'\phpDocumentor\Reflection\ClassReflector\MethodReflector',
177+
$class_reflector->getMethod('someMethod')
178+
);
179+
$this->assertNull($class_reflector->getMethod('someOtherMethod'));
180+
}
152181
}

0 commit comments

Comments
 (0)