С версии: 2.0
Автор: Carsten Brandt (mail@cebe.cc)
Наследование: extends yii\base\Object
Пример #1
0
 /**
  * @param \phpDocumentor\Reflection\FunctionReflector $reflector
  * @param Context $context
  * @param array $config
  */
 public function __construct($reflector = null, $context = null, $config = [])
 {
     parent::__construct($reflector, $context, $config);
     if ($reflector === null) {
         return;
     }
     $this->isReturnByReference = $reflector->isByRef();
     foreach ($reflector->getArguments() as $arg) {
         $arg = new ParamDoc($arg, $context, ['sourceFile' => $this->sourceFile]);
         $this->params[$arg->name] = $arg;
     }
     foreach ($this->tags as $i => $tag) {
         if ($tag instanceof ThrowsTag) {
             $this->exceptions[$tag->getType()] = $tag->getDescription();
             unset($this->tags[$i]);
         } elseif ($tag instanceof PropertyTag) {
             // ignore property tag
         } elseif ($tag instanceof ParamTag) {
             $paramName = $tag->getVariableName();
             if (!isset($this->params[$paramName]) && $context !== null) {
                 $context->errors[] = ['line' => $this->startLine, 'file' => $this->sourceFile, 'message' => "Undefined parameter documented: {$paramName} in {$this->name}()."];
                 continue;
             }
             $this->params[$paramName]->description = ucfirst($tag->getDescription());
             $this->params[$paramName]->type = $tag->getType();
             $this->params[$paramName]->types = $tag->getTypes();
             unset($this->tags[$i]);
         } elseif ($tag instanceof ReturnTag) {
             $this->returnType = $tag->getType();
             $this->returnTypes = $tag->getTypes();
             $this->return = ucfirst($tag->getDescription());
             unset($this->tags[$i]);
         }
     }
 }
Пример #2
0
 /**
  * @param \phpDocumentor\Reflection\ClassReflector\PropertyReflector $reflector
  * @param Context                                                    $context
  * @param array                                                      $config
  */
 public function __construct($reflector = null, $context = null, $config = [])
 {
     parent::__construct($reflector, $context, $config);
     if ($reflector === null) {
         return;
     }
     $this->visibility = $reflector->getVisibility();
     $this->isStatic = $reflector->isStatic();
     // bypass $reflector->getDefault() for short array syntax
     if ($reflector->getNode()->default) {
         $this->defaultValue = PrettyPrinter::getRepresentationOfValue($reflector->getNode()->default);
     }
     $hasInheritdoc = false;
     foreach ($this->tags as $tag) {
         if ($tag->getName() === 'inheritdoc') {
             $hasInheritdoc = true;
         }
         if ($tag instanceof VarTag) {
             $this->type = $tag->getType();
             $this->types = $tag->getTypes();
             $this->description = ucfirst($tag->getDescription());
             if (($pos = strpos($this->description, '.')) !== false) {
                 $this->shortDescription = substr($this->description, 0, $pos + 1);
             } else {
                 $this->shortDescription = $this->description;
             }
         }
     }
     if (empty($this->shortDescription) && $context !== null && !$hasInheritdoc) {
         $context->errors[] = ['line' => $this->startLine, 'file' => $this->sourceFile, 'message' => "No short description for element '{$this->name}'"];
     }
 }
Пример #3
0
 /**
  * @param \phpDocumentor\Reflection\ClassReflector\ConstantReflector $reflector
  * @param Context $context
  * @param array $config
  */
 public function __construct($reflector = null, $context = null, $config = [])
 {
     parent::__construct($reflector, $context, $config);
     if ($reflector === null) {
         return;
     }
     foreach ($this->tags as $i => $tag) {
         if ($tag->getName() == 'event') {
             $eventTag = new ReturnTag('event', $tag->getContent(), $tag->getDocBlock(), $tag->getLocation());
             $this->type = $eventTag->getType();
             $this->types = $eventTag->getTypes();
             $this->description = ucfirst($eventTag->getDescription());
             $this->shortDescription = BaseDoc::extractFirstSentence($this->description);
             unset($this->tags[$i]);
         }
     }
 }
 /**
  * @param BaseDoc|string $context
  * @return string
  */
 private function resolveNamespace($context)
 {
     // TODO use phpdoc Context for this
     if ($context === null) {
         return '';
     }
     if ($context instanceof TypeDoc) {
         return $context->namespace;
     }
     if ($context->hasProperty('definedBy')) {
         $type = $this->apiContext->getType($context);
         if ($type !== null) {
             return $type->namespace;
         }
     }
     return '';
 }
Пример #5
0
 /**
  * Add properties for getters and setters if class is subclass of [[\yii\base\Object]].
  * @param ClassDoc $class
  */
 protected function handlePropertyFeature($class)
 {
     if (!$this->isSubclassOf($class, 'yii\\base\\Object')) {
         return;
     }
     foreach ($class->getPublicMethods() as $name => $method) {
         if ($method->isStatic) {
             continue;
         }
         if (!strncmp($name, 'get', 3) && strlen($name) > 3 && $this->hasNonOptionalParams($method)) {
             $propertyName = '$' . lcfirst(substr($method->name, 3));
             if (isset($class->properties[$propertyName])) {
                 $property = $class->properties[$propertyName];
                 if ($property->getter === null && $property->setter === null) {
                     $this->errors[] = ['line' => $property->startLine, 'file' => $class->sourceFile, 'message' => "Property {$propertyName} conflicts with a defined getter {$method->name} in {$class->name}."];
                 }
                 $property->getter = $method;
             } else {
                 $class->properties[$propertyName] = new PropertyDoc(null, $this, ['name' => $propertyName, 'definedBy' => $method->definedBy, 'sourceFile' => $class->sourceFile, 'visibility' => 'public', 'isStatic' => false, 'type' => $method->returnType, 'types' => $method->returnTypes, 'shortDescription' => BaseDoc::extractFirstSentence($method->return), 'description' => $method->return, 'getter' => $method]);
             }
         }
         if (!strncmp($name, 'set', 3) && strlen($name) > 3 && $this->hasNonOptionalParams($method, 1)) {
             $propertyName = '$' . lcfirst(substr($method->name, 3));
             if (isset($class->properties[$propertyName])) {
                 $property = $class->properties[$propertyName];
                 if ($property->getter === null && $property->setter === null) {
                     $this->errors[] = ['line' => $property->startLine, 'file' => $class->sourceFile, 'message' => "Property {$propertyName} conflicts with a defined setter {$method->name} in {$class->name}."];
                 }
                 $property->setter = $method;
             } else {
                 $param = $this->getFirstNotOptionalParameter($method);
                 $class->properties[$propertyName] = new PropertyDoc(null, $this, ['name' => $propertyName, 'definedBy' => $method->definedBy, 'sourceFile' => $class->sourceFile, 'visibility' => 'public', 'isStatic' => false, 'type' => $param->type, 'types' => $param->types, 'shortDescription' => BaseDoc::extractFirstSentence($param->description), 'description' => $param->description, 'setter' => $method]);
             }
         }
     }
 }
Пример #6
0
 /**
  * @param \phpDocumentor\Reflection\InterfaceReflector $reflector
  * @param Context $context
  * @param array $config
  */
 public function __construct($reflector = null, $context = null, $config = [])
 {
     parent::__construct($reflector, $context, $config);
     if ($reflector === null) {
         return;
     }
     foreach ($this->tags as $i => $tag) {
         if ($tag instanceof AuthorTag) {
             $this->authors[$tag->getAuthorName()] = $tag->getAuthorEmail();
             unset($this->tags[$i]);
         } else {
             if ($tag->getName() == 'package') {
                 $this->namespace = $tag->getContent();
                 unset($this->tags[$i]);
             }
         }
     }
     if (empty($this->namespace)) {
         $this->namespace = trim(StringHelper::dirname($this->name), '\\');
     }
     foreach ($reflector->getProperties() as $propertyReflector) {
         if ($propertyReflector->getVisibility() != 'private') {
             $property = new PropertyDoc($propertyReflector, $context, ['sourceFile' => $this->sourceFile]);
             $property->definedBy = $this->name;
             $this->properties[$property->name] = $property;
         }
     }
     foreach ($reflector->getMethods() as $methodReflector) {
         if ($methodReflector->getVisibility() != 'private') {
             $method = new MethodDoc($methodReflector, $context, ['sourceFile' => $this->sourceFile]);
             $method->definedBy = $this->name;
             $this->methods[$method->name] = $method;
         }
     }
 }