コード例 #1
0
 /**
  * Overwrites the type and description in the Argument Descriptor with that from the tag if the names match.
  *
  * @param ArgumentReflector  $argument
  * @param ParamDescriptor    $paramDescriptor
  * @param ArgumentDescriptor $argumentDescriptor
  *
  * @return void
  */
 protected function overwriteTypeAndDescriptionFromParamTag(ArgumentReflector $argument, ParamDescriptor $paramDescriptor, ArgumentDescriptor $argumentDescriptor)
 {
     if ($paramDescriptor->getVariableName() != $argument->getName()) {
         return;
     }
     $argumentDescriptor->setDescription($paramDescriptor->getDescription());
     $argumentDescriptor->setTypes($paramDescriptor->getTypes() ?: $this->builder->buildDescriptor(new Collection(array($argument->getType() ?: 'mixed'))));
 }
コード例 #2
0
 /**
  * Initializes the reflector using the function statement object of
  * PHP-Parser.
  *
  * @param \PHPParser_Node_Stmt $node Function object coming from PHP-Parser.
  */
 public function __construct(\PHPParser_Node_Stmt $node)
 {
     parent::__construct($node);
     /** @var \PHPParser_Node_Param $param  */
     foreach ($node->params as $param) {
         $reflector = new FunctionReflector\ArgumentReflector($param);
         $this->arguments[$reflector->getName()] = $reflector;
     }
 }
コード例 #3
0
 /**
  * Initializes the reflector using the function statement object of
  * PHP-Parser.
  *
  * @param \PhpParser\Node\Stmt $node    Function object coming from PHP-Parser.
  * @param Context             $context The context in which the node occurs.
  */
 public function __construct(\PhpParser\Node\Stmt $node, Context $context)
 {
     parent::__construct($node, $context);
     /** @var \PhpParser\Node\Param $param  */
     foreach ($node->params as $param) {
         $reflector = new FunctionReflector\ArgumentReflector($param, $context);
         $this->arguments[$reflector->getName()] = $reflector;
     }
 }
コード例 #4
0
 /**
  * Exports the given reflection object to the parent XML element.
  *
  * This method creates a new child element on the given parent XML element
  * and takes the properties of the Reflection argument and sets the
  * elements and attributes on the child.
  *
  * If a child DOMElement is provided then the properties and attributes are
  * set on this but the child element is not appended onto the parent. This
  * is the responsibility of the invoker. Essentially this means that the
  * $parent argument is ignored in this case.
  *
  * @param \DOMElement       $parent   The parent element to augment.
  * @param ArgumentReflector $argument The data source.
  * @param \DOMElement       $child    Optional: child element to use instead
  *     of creating a new one on the $parent.
  *
  * @return void
  */
 public function export(\DOMElement $parent, $argument, \DOMElement $child = null)
 {
     if (!$child) {
         $child = new \DOMElement('argument');
         $parent->appendChild($child);
     }
     $child->setAttribute('line', $argument->getLineNumber());
     $child->appendChild(new \DOMElement('name', $argument->getName()));
     $child->appendChild(new \DOMElement('default'))->appendChild(new \DOMText($argument->getDefault()));
     $type = $argument->getType();
     $child->appendChild(new \DOMElement('type', $type ? $type : ''));
 }
コード例 #5
0
 /**
  * Exports the given reflection object to the parent XML element.
  *
  * This method creates a new child element on the given parent XML element
  * and takes the properties of the Reflection argument and sets the
  * elements and attributes on the child.
  *
  * If a child DOMElement is provided then the properties and attributes are
  * set on this but the child element is not appended onto the parent. This
  * is the responsibility of the invoker. Essentially this means that the
  * $parent argument is ignored in this case.
  *
  * @param \DOMElement                        $parent   The parent element to
  *     augment.
  * @param \phpDocumentor\Reflection\FunctionReflector\ArgumentReflector $argument The data source.
  * @param \DOMElement                        $child    Optional: child
  *     element to use instead of creating a new one on the $parent.
  *
  * @return void
  */
 public function export(\DOMElement $parent, $argument, \DOMElement $child = null)
 {
     if (!$child) {
         $child = new \DOMElement('argument');
         $parent->appendChild($child);
     }
     $child->setAttribute('line', $argument->getLineNumber());
     $child->appendChild(new \DOMElement('name', $argument->getName()));
     $default = new \DOMElement('default');
     $child->appendChild($default);
     /** @var \DOMDocument $dom_document */
     $dom_document = $child->ownerDocument;
     $default->appendChild($dom_document->createCDATASection($argument->getDefault()));
     $child->appendChild(new \DOMElement('type', $argument->getType()));
 }
コード例 #6
0
ファイル: ParamDoc.php プロジェクト: sciurodont/yii2
 /**
  * @param \phpDocumentor\Reflection\FunctionReflector\ArgumentReflector $reflector
  * @param Context $context
  * @param array $config
  */
 public function __construct($reflector = null, $context = null, $config = [])
 {
     parent::__construct($config);
     if ($reflector === null) {
         return;
     }
     $this->name = $reflector->getName();
     $this->typeHint = $reflector->getType();
     $this->isOptional = $reflector->getDefault() !== null;
     // bypass $reflector->getDefault() for short array syntax
     if ($reflector->getNode()->default) {
         $this->defaultValue = PrettyPrinter::getRepresentationOfValue($reflector->getNode()->default);
     }
     $this->isPassedByReference = $reflector->isByRef();
 }
コード例 #7
0
 /**
  * Creates a Descriptor from the provided data.
  *
  * @param ArgumentReflector $data
  * @param ParamDescriptor[] $params
  *
  * @return ArgumentDescriptor
  */
 public function create($data, $params = array())
 {
     $argumentDescriptor = new ArgumentDescriptor();
     $argumentDescriptor->setName($data->getName());
     $argumentDescriptor->setTypes($data->getType() ? array($data->getType()) : array());
     /** @var ParamDescriptor $tag */
     foreach ($params as $tag) {
         if ($tag->getVariableName() == $data->getName()) {
             $argumentDescriptor->setDescription($tag->getDescription());
             $types = $tag->getTypes() ?: array($data->getType() ?: 'mixed');
             $argumentDescriptor->setTypes($types);
         }
     }
     $argumentDescriptor->setDefault($data->getDefault());
     return $argumentDescriptor;
 }
コード例 #8
0
 /**
  * Checks the typehint of the argument versus the @param tag.
  *
  * If the argument has no typehint we do not check anything. When multiple
  * type are given then the typehint needs to be one of them.
  *
  * @param \phpDocumentor\Reflection\DocBlock\Tag\ParamTag $param
  * @param \phpDocumentor\Reflection\FunctionReflector\ArgumentReflector $argument
  *
  * @return bool whether an issue occurred
  */
 protected function doesArgumentTypehintMatchParam(\phpDocumentor\Reflection\DocBlock\Tag\ParamTag $param, \phpDocumentor\Reflection\FunctionReflector\ArgumentReflector $argument)
 {
     if (!$argument->getType() || in_array($argument->getType(), $param->getTypes())) {
         return true;
     }
     $this->logParserError('ERROR', 50016, $this->lineNumber, array($argument->getName(), $this->entityName . '()'));
     return false;
 }
コード例 #9
0
 /**
  * Checks the typehint of the argument versus the @param tag.
  *
  * If the argument has no typehint we do not check anything. When multiple
  * type are given then the typehint needs to be one of them.
  *
  * @param ParamTag          $param
  * @param ArgumentReflector $argument
  *
  * @return Error|null
  */
 protected function doesArgumentTypehintMatchParam(ParamTag $param, ArgumentReflector $argument, $element)
 {
     if (!$argument->getType() || in_array($argument->getType(), $param->getTypes())) {
         return null;
     } elseif ($argument->getType() == 'array' && substr($param->getType(), -2) == '[]') {
         return null;
     }
     return new Error(LogLevel::ERROR, 'PPC:ERR-50016', $argument->getLinenumber(), array($argument->getName(), $element->getName()));
 }