/** * Creates a Descriptor from the provided data. * * @param ClassReflector $data * * @return ClassDescriptor */ public function create($data) { $classDescriptor = new ClassDescriptor(); $classDescriptor->setFullyQualifiedStructuralElementName($data->getName()); $classDescriptor->setName($data->getShortName()); $classDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: ''); $classDescriptor->setLine($data->getLinenumber()); $classDescriptor->setParent($data->getParentClass()); $classDescriptor->setAbstract($data->isAbstract()); $classDescriptor->setFinal($data->isFinal()); // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself $classDescriptor->setNamespace('\\' . (strtolower($data->getNamespace()) == 'global' ? '' : $data->getNamespace())); foreach ($data->getInterfaces() as $interfaceClassName) { $classDescriptor->getInterfaces()->set($interfaceClassName, $interfaceClassName); } $fqcn = $classDescriptor->getFullyQualifiedStructuralElementName(); $namespace = substr($fqcn, 0, strrpos($fqcn, '\\')); $classDescriptor->setNamespace($namespace); $this->assembleDocBlock($data->getDocBlock(), $classDescriptor); $this->addConstants($data->getConstants(), $classDescriptor); $this->addProperties($data->getProperties(), $classDescriptor); $this->addMethods($data->getMethods(), $classDescriptor); $this->addUses($data->getTraits(), $classDescriptor); return $classDescriptor; }
/** * @covers phpDocumentor\Descriptor\ClassDescriptor::getMagicMethods */ public function testGetMagicMethods() { $methodName = 'methodName'; $description = 'description'; $response = array('string'); $arguments = array('name' => 'argument'); $this->assertEquals(0, $this->fixture->getMagicMethods()->count()); $methodMock = m::mock('phpDocumentor\\Descriptor\\Tag\\MethodDescriptor'); $methodMock->shouldReceive('getMethodName')->andReturn($methodName); $methodMock->shouldReceive('getDescription')->andReturn($description); $methodMock->shouldReceive('getResponse')->andReturn($response); $methodMock->shouldReceive('getArguments')->andReturn($arguments); $this->fixture->getTags()->get('method', new Collection())->add($methodMock); $magicMethods = $this->fixture->getMagicMethods(); $this->assertCount(1, $magicMethods); /** @var MethodDescriptor $magicMethod */ $magicMethod = current($magicMethods->getAll()); $this->assertEquals($methodName, $magicMethod->getName()); $this->assertEquals($description, $magicMethod->getDescription()); $this->assertEquals($response, $magicMethod->getResponse()); $mock = m::mock('phpDocumentor\\Descriptor\\ClassDescriptor'); $mock->shouldReceive('getMagicMethods')->andReturn(new Collection(array('magicMethods'))); $this->fixture->setParent($mock); $magicMethods = $this->fixture->getMagicMethods(); $this->assertCount(2, $magicMethods); }
/** * @param string $name The name of the current property. * * @return PropertyDescriptor */ protected function whenFixtureHasPropertyInParentClassWithSameName($name) { $result = new PropertyDescriptor(); $result->setName($name); $parent = new ClassDescriptor(); $parent->getProperties()->set($name, $result); $class = new ClassDescriptor(); $class->setParent($parent); $this->fixture->setParent($class); return $result; }
/** * Returns a class with the given parent set. * * @param string|DescriptorAbstract $parent * * @return ClassDescriptor */ protected function givenAClassWithParent($parent) { $classDescriptor1 = new ClassDescriptor(); $classDescriptor1->setParent($parent); return $classDescriptor1; }
/** * @return ClassDescriptor */ protected function whenFixtureHasParentClass() { $class = new ClassDescriptor(); $this->fixture->setParent($class); return $class; }