/** * @param ClassDescriptor $class * * @return MethodDescriptor[] */ public function getPublicMethods($class) { if (!$class instanceof ClassDescriptor) { return []; } $methods = $class->getMagicMethods()->merge($class->getInheritedMethods())->merge($class->getMethods()); return array_filter($methods->getAll(), function (MethodDescriptor $method) { return $method->getVisibility() == 'public'; }); }
/** * @covers phpDocumentor\Descriptor\ClassDescriptor::getInheritedMethods * @ticket https://github.com/phpDocumentor/phpDocumentor2/issues/1307 */ public function testRetrievingInheritedMethodsDoesNotCrashWhenUsedTraitIsNotInProject() { // Arrange $expected = array(); // unknown traits are not converted to TraitDescriptors but kept as strings $this->fixture->setUsedTraits(new Collection(array('unknownTrait'))); // Act $result = $this->fixture->getInheritedMethods(); // Assert $this->assertInstanceOf('phpDocumentor\\Descriptor\\Collection', $result); $this->assertSame($expected, $result->getAll()); }
/** * @covers phpDocumentor\Descriptor\ClassDescriptor::getInheritedMethods */ public function testRetrievingInheritedMethodsReturnsCollectionWithParent() { $collectionMock = m::mock('phpDocumentor\\Descriptor\\Collection'); $collectionMock->shouldReceive('get'); $mock = m::mock('phpDocumentor\\Descriptor\\ClassDescriptor'); $mock->shouldReceive('getMethods')->andReturn(new Collection(array('methods'))); $mock->shouldReceive('getInheritedMethods')->andReturn(new Collection(array('inherited'))); $this->fixture->setParent($mock); $result = $this->fixture->getInheritedMethods(); $this->assertInstanceOf('phpDocumentor\\Descriptor\\Collection', $result); $expected = array('methods', 'inherited'); $this->assertSame($expected, $result->getAll()); }