コード例 #1
0
 /**
  * @param string $class
  * @return string
  */
 protected function createPhpDocs($class)
 {
     $reflection = new \ReflectionClass($class);
     $namespace = $reflection->getNamespaceName();
     $classname = $reflection->getShortName();
     $originalDoc = $reflection->getDocComment();
     if ($this->reset) {
         $phpdoc = new DocBlock('', new Context($namespace));
     } else {
         $phpdoc = new DocBlock($reflection, new Context($namespace));
     }
     if (!$phpdoc->getText()) {
         $phpdoc->setText($class);
     }
     $properties = array();
     $methods = array();
     foreach ($phpdoc->getTags() as $tag) {
         $name = $tag->getName();
         if ($name == "property" || $name == "property-read" || $name == "property-write") {
             $properties[] = $tag->getVariableName();
         } elseif ($name == "method") {
             $methods[] = $tag->getMethodName();
         }
     }
     foreach ($this->properties as $name => $property) {
         $name = "\${$name}";
         if (in_array($name, $properties)) {
             continue;
         }
         if ($property['read'] && $property['write']) {
             $attr = 'property';
         } elseif ($property['write']) {
             $attr = 'property-write';
         } else {
             $attr = 'property-read';
         }
         if ($this->hasCamelCaseModelProperties()) {
             $name = Str::camel($name);
         }
         $tagLine = trim("@{$attr} {$property['type']} {$name} {$property['comment']}");
         $tag = Tag::createInstance($tagLine, $phpdoc);
         $phpdoc->appendTag($tag);
     }
     foreach ($this->methods as $name => $method) {
         if (in_array($name, $methods)) {
             continue;
         }
         $arguments = implode(', ', $method['arguments']);
         $tag = Tag::createInstance("@method static {$method['type']} {$name}({$arguments})", $phpdoc);
         $phpdoc->appendTag($tag);
     }
     if ($this->write && !$phpdoc->getTagsByName('mixin')) {
         $phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc));
     }
     $serializer = new DocBlockSerializer();
     $serializer->getDocComment($phpdoc);
     $docComment = $serializer->getDocComment($phpdoc);
     if ($this->write) {
         $filename = $reflection->getFileName();
         $contents = $this->files->get($filename);
         if ($originalDoc) {
             $contents = str_replace($originalDoc, $docComment, $contents);
         } else {
             $needle = "class {$classname}";
             $replace = "{$docComment}\nclass {$classname}";
             $pos = strpos($contents, $needle);
             if ($pos !== false) {
                 $contents = substr_replace($contents, $replace, $pos, strlen($needle));
             }
         }
         if ($this->files->put($filename, $contents)) {
             $this->info('Written new phpDocBlock to ' . $filename);
         }
     }
     $output = "namespace {$namespace}{\n{$docComment}\n\tclass {$classname} extends \\Eloquent {}\n}\n\n";
     return $output;
 }
コード例 #2
0
ファイル: Method.php プロジェクト: Nayfania/Review-Service
 /**
  * Get the description and get the inherited docs.
  *
  * @param DocBlock $phpdoc
  */
 protected function normalizeDescription(DocBlock $phpdoc)
 {
     //Get the short + long description from the DocBlock
     $description = $phpdoc->getText();
     //Loop through parents/interfaces, to fill in {@inheritdoc}
     if (strpos($description, '{@inheritdoc}') !== false) {
         $inheritdoc = $this->getInheritDoc($this->method);
         $inheritDescription = $inheritdoc->getText();
         $description = str_replace('{@inheritdoc}', $inheritDescription, $description);
         $phpdoc->setText($description);
         $this->normalizeParams($inheritdoc);
         $this->normalizeReturn($inheritdoc);
         //Add the tags that are inherited
         $inheritTags = $inheritdoc->getTags();
         if ($inheritTags) {
             /** @var Tag $tag */
             foreach ($inheritTags as $tag) {
                 $tag->setDocBlock();
                 $phpdoc->appendTag($tag);
             }
         }
     }
 }