Exemple #1
0
 /**
  * @param string $namespace
  * @param Use_[] $uses
  * @param PhpParserClass $class
  * @param File $file
  */
 public function __construct($namespace, array $uses, PhpParserClass $class, File $file)
 {
     $this->namespace = $namespace;
     $this->file = $file;
     $this->node = $class;
     $this->uses = $uses;
     $this->fqn = join('\\', array_filter([$namespace, $class->name]));
     $this->resolveNames();
     if (NULL === $this->fqParent && isset($class->extends)) {
         throw new \RuntimeException('Something is amiss, resolved parent name and actual parent differ in ' . $file->getSplFile()->getRealPath() . ':' . $class->getLine());
     }
     if (count($this->implements) !== count($class->implements)) {
         throw new \RuntimeException('Something is amiss, resolved ' . count($this->implements) . ' interface(s) but found ' . count($class->implements) . ' actual interface(s) in ' . $file->getSplFile()->getRealPath() . ':' . $class->getLine());
     }
 }
 /**
  * @return int
  */
 protected function getNewTraitUseLine()
 {
     $line = $this->classAbstractTree->getLine() + 1;
     /* // -1 because we want place it before
        // another -1 because phpParser counts lines from 1
        $line = array_values($this->classAbstractTree->stmts)[0]->getLine() - 2;*/
     /*
      * If class definition is like this:
      *
      * class Foo
      * {
      *     // Content
      * }
      *
      * not like this:
      *
      * class Foo {
      *     // Content
      * }
      *
      * we need to subtract one line
      */
     if (strpos($this->content[$this->classAbstractTree->getLine() - 1], '{') !== false) {
         --$line;
     }
     return $line;
 }
 public function store_class(Node\Stmt\Class_ $class)
 {
     if ($class->extends) {
         $parent = end($class->extends->parts);
         $parent_namespace = implode('\\', array_slice($class->extends->parts, 0, -1));
     } else {
         $parent = '';
         $parent_namespace = '';
     }
     $description = '';
     if ($comments = $class->getAttribute('comments')) {
         $phpdoc = new DocBlock($comments[0]->getText());
         $description = $phpdoc->getShortDescription();
         // short circuit @ignore functions
         if ($phpdoc->hasTag('ignore')) {
             return;
         }
     }
     $this->store_model('classes', array('class' => $class->name, 'namespace' => !empty($class->namespacedName) ? implode('\\', array_slice($class->namespacedName->parts, 0, -1)) : '', 'file' => $this->_current_file, 'line' => $class->getLine(), 'parent' => $parent, 'parent_namespace' => $parent_namespace, 'description' => $description));
     $methods = array_filter($class->stmts, function ($node) {
         return $node instanceof Node\Stmt\ClassMethod;
     });
     foreach ($methods as $method) {
         $this->store_class_method($class, $method);
     }
     $constants = array_filter($class->stmts, function ($node) {
         return $node instanceof Node\Stmt\ClassConst;
     });
     foreach ($constants as $constant) {
         $this->store_class_constant($class, $constant);
     }
 }
 /**
  * @param Node\Stmt\Class_ $node
  */
 protected function parseClassNode(Node\Stmt\Class_ $node)
 {
     if (!isset($node->namespacedName)) {
         return;
         // Ticket #45 - This could potentially not be set for PHP 7 anonymous classes.
     }
     $this->currentStructuralElement = $node;
     $interfaces = [];
     /** @var Node\Name $implementedName */
     foreach ($node->implements as $implementedName) {
         $interfaces[] = $implementedName->toString();
     }
     $this->structuralElements[$node->namespacedName->toString()] = ['name' => $node->name, 'type' => 'class', 'startLine' => $node->getLine(), 'isAbstract' => $node->isAbstract(), 'docComment' => $node->getDocComment() ? $node->getDocComment()->getText() : null, 'parents' => $node->extends ? [$node->extends->toString()] : [], 'interfaces' => $interfaces, 'traits' => [], 'methods' => [], 'properties' => [], 'constants' => []];
 }
 public function getLine()
 {
     return $this->classBefore->getLine();
 }
 /**
  * @return int
  */
 public function getLine()
 {
     return $this->classAfter->getLine();
 }