/** * Generates a URL from the given node or returns false if unable. * * @param string|Descriptor\PropertyDescriptor $node * * @return string|false */ public function __invoke($node) { if (!$node instanceof Descriptor\PropertyDescriptor) { return false; } $converter = new QualifiedNameToUrlConverter(); $className = $node->getParent()->getFullyQualifiedStructuralElementName(); return '/classes/' . $converter->fromClass($className) . '.html#property_' . $node->getName(); }
/** * Checks if the passed value is valid. * * @param PropertyDescriptor $value The value that should be validated * @param Constraint $constraint The constraint for the validation * * @throws ConstraintDefinitionException if this is not a constraint on a PropertyDescriptor object. */ public function validate($value, Constraint $constraint) { if (!$value instanceof PropertyDescriptor) { throw new ConstraintDefinitionException('The Property\\HasSummary validator may only be used on property objects'); } $var = $value->getVar(); if (!$value->getSummary() && ($var->count() == 0 || !current($var->getAll())->getDescription())) { $this->context->addViolationAt('summary', $constraint->message); } }
/** * Export the given reflected property definition to the provided parent element. * * @param \DOMElement $parent Element to augment. * @param PropertyDescriptor $property Element to export. * * @return \DOMElement */ public function convert(\DOMElement $parent, PropertyDescriptor $property) { $fullyQualifiedNamespaceName = $property->getNamespace() instanceof NamespaceDescriptor ? $property->getNamespace()->getFullyQualifiedStructuralElementName() : $parent->getAttribute('namespace'); $child = new \DOMElement('property'); $parent->appendChild($child); $child->setAttribute('static', var_export($property->isStatic(), true)); $child->setAttribute('visibility', $property->getVisibility()); $child->setAttribute('namespace', $fullyQualifiedNamespaceName); $child->setAttribute('line', $property->getLine()); $child->appendChild(new \DOMElement('name', '$' . $property->getName())); $child->appendChild(new \DOMElement('full_name', $property->getFullyQualifiedStructuralElementName())); $child->appendChild(new \DOMElement('default'))->appendChild(new \DOMText($property->getDefault())); $this->docBlockConverter->convert($child, $property); return $child; }
/** * @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; }
/** * Creates a Descriptor from the provided data. * * @param PropertyReflector $data * * @return PropertyDescriptor */ public function create($data) { $propertyDescriptor = new PropertyDescriptor(); $propertyDescriptor->setFullyQualifiedStructuralElementName($data->getName()); $propertyDescriptor->setName($data->getShortName()); $propertyDescriptor->setVisibility($data->getVisibility() ?: 'public'); $propertyDescriptor->setStatic($data->isStatic()); $propertyDescriptor->setDefault($data->getDefault()); $this->assembleDocBlock($data->getDocBlock(), $propertyDescriptor); $propertyDescriptor->setLine($data->getLinenumber()); return $propertyDescriptor; }
/** * Export the given property definition to the provided parent element. * * @param \DOMElement $parent Element to augment. * @param PropertyDescriptor $property Element to export. * * @return void */ public function buildProperty(\DOMElement $parent, PropertyDescriptor $property) { $child = new \DOMElement('property'); $parent->appendChild($child); $child->setAttribute('static', $property->isStatic() ? 'true' : 'false'); $child->setAttribute('visibility', $property->getVisibility()); $child->setAttribute('line', $property->getLine()); $namespaceFqnn = $property->getNamespace() ? $property->getNamespace()->getFullyQualifiedStructuralElementName() : $parent->getAttribute('namespace'); $child->setAttribute('namespace', $namespaceFqnn); $child->appendChild(new \DOMElement('name', '$' . $property->getName())); $child->appendChild(new \DOMElement('default'))->appendChild(new \DOMText($property->getDefault())); $this->buildDocBlock($child, $property); }
/** * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getSubElements */ public function testAddPropertiesToIndex() { $file1 = $this->project->getFiles()->get(0); $classDescriptor1 = new ClassDescriptor(); $classDescriptor1->setFullyQualifiedStructuralElementName('My\\Space\\Class1'); $file1->getClasses()->add($classDescriptor1); $classPropertyDescriptor1 = new PropertyDescriptor(); $classPropertyDescriptor1->setFullyQualifiedStructuralElementName('My\\Space\\Class1::PROPERTY'); $classDescriptor1->getProperties()->add($classPropertyDescriptor1); $file2 = $this->project->getFiles()->get(1); $classDescriptor2 = new ClassDescriptor(); $classDescriptor2->setFullyQualifiedStructuralElementName('My\\Space\\Class2'); $file2->getClasses()->add($classDescriptor2); $classPropertyDescriptor2 = new PropertyDescriptor(); $classPropertyDescriptor2->setFullyQualifiedStructuralElementName('My\\Space\\Class2::PROPERTY'); $classDescriptor2->getProperties()->add($classPropertyDescriptor2); $this->fixture->execute($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $this->assertCount(4, $elements); // note the addition of the dollar sign in front of the property name $this->assertSame(array('My\\Space\\Class1', 'My\\Space\\Class1::$PROPERTY', 'My\\Space\\Class2', 'My\\Space\\Class2::$PROPERTY'), array_keys($elements)); $this->assertSame(array($classDescriptor1, $classPropertyDescriptor1, $classDescriptor2, $classPropertyDescriptor2), array_values($elements)); // class properties are not indexed separately $this->assertNull($this->project->getIndexes()->get('properties')); }
/** * Generates a URL from the given node or returns false if unable. * * @param string|Descriptor\PropertyDescriptor $node * * @return string|false */ public function __invoke($node) { $converter = new QualifiedNameToUrlConverter(); $className = $node->getParent()->getFullyQualifiedStructuralElementName(); return '/classes/' . $converter->fromClass($className) . '.html#property_' . $node->getName(); }