yii\apidoc\models\Context::inheritDocs PHP Method

inheritDocs() protected method

Inhertit docsblocks using @inheritDoc tag.
See also: http://phpdoc.org/docs/latest/guides/inheritance.html
protected inheritDocs ( yii\apidoc\models\ClassDoc $class )
$class yii\apidoc\models\ClassDoc
    protected function inheritDocs($class)
    {
        // inherit for properties
        foreach ($class->properties as $p) {
            if ($p->hasTag('inheritdoc') && ($inheritTag = $p->getFirstTag('inheritdoc')) !== null) {
                $inheritedProperty = $this->inheritPropertyRecursive($p, $class);
                if (!$inheritedProperty) {
                    $this->errors[] = ['line' => $p->startLine, 'file' => $class->sourceFile, 'message' => "Method {$p->name} has no parent to inherit from in {$class->name}."];
                    continue;
                }
                // set all properties that are empty.
                foreach (['shortDescription', 'type', 'types'] as $property) {
                    if (empty($p->{$property}) || is_string($p->{$property}) && trim($p->{$property}) === '') {
                        $p->{$property} = $inheritedProperty->{$property};
                    }
                }
                // descriptions will be concatenated.
                $p->description = trim($p->description) . "\n\n" . trim($inheritedProperty->description) . "\n\n" . $inheritTag->getContent();
                $p->removeTag('inheritdoc');
            }
        }
        // inherit for methods
        foreach ($class->methods as $m) {
            if ($m->hasTag('inheritdoc') && ($inheritTag = $m->getFirstTag('inheritdoc')) !== null) {
                $inheritedMethod = $this->inheritMethodRecursive($m, $class);
                if (!$inheritedMethod) {
                    $this->errors[] = ['line' => $m->startLine, 'file' => $class->sourceFile, 'message' => "Method {$m->name} has no parent to inherit from in {$class->name}."];
                    continue;
                }
                // set all properties that are empty.
                foreach (['shortDescription', 'return', 'returnType', 'returnTypes', 'exceptions'] as $property) {
                    if (empty($m->{$property}) || is_string($m->{$property}) && trim($m->{$property}) === '') {
                        $m->{$property} = $inheritedMethod->{$property};
                    }
                }
                // descriptions will be concatenated.
                $m->description = trim($m->description) . "\n\n" . trim($inheritedMethod->description) . "\n\n" . $inheritTag->getContent();
                foreach ($m->params as $i => $param) {
                    if (!isset($inheritedMethod->params[$i])) {
                        $this->errors[] = ['line' => $m->startLine, 'file' => $class->sourceFile, 'message' => "Method param {$i} does not exist in parent method, @inheritdoc not possible in {$m->name} in {$class->name}."];
                        continue;
                    }
                    if (empty($param->description) || trim($param->description) === '') {
                        $param->description = $inheritedMethod->params[$i]->description;
                    }
                    if (empty($param->type) || trim($param->type) === '') {
                        $param->type = $inheritedMethod->params[$i]->type;
                    }
                    if (empty($param->types)) {
                        $param->types = $inheritedMethod->params[$i]->types;
                    }
                }
                $m->removeTag('inheritdoc');
            }
        }
    }