Skip to content

Commit

Permalink
Merge pull request #78 from lvht/master
Browse files Browse the repository at this point in the history
migrate to php-parser v3.x
  • Loading branch information
gianarb authored Feb 5, 2018
2 parents 19b59d6 + 31247f8 commit eedfec3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1,046 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.test_fs
build/
vendor/
composer.lock
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7
- hhvm
Expand Down
42 changes: 23 additions & 19 deletions PHPCtags.class.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
use PhpParser\ParserFactory;
use PhpParser\Node\Stmt;
use PhpParser\Node\Expr;

class PHPCtags
{
const VERSION = '0.6.1';
Expand Down Expand Up @@ -28,7 +32,7 @@ class PHPCtags

public function __construct($options)
{
$this->mParser = new PHPParser_Parser(new PHPParser_Lexer);
$this->mParser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$this->mLines = array();
$this->mOptions = $options;
$this->filecount = 0;
Expand Down Expand Up @@ -128,7 +132,7 @@ private function struct($node, $reset=FALSE, $parent=array())
foreach ($node as $subNode) {
$this->struct($subNode);
}
} elseif ($node instanceof PHPParser_Node_Stmt_Class) {
} elseif ($node instanceof Stmt\Class_) {
$kind = 'c';
$name = $node->name;
$extends = $node->extends;
Expand All @@ -137,90 +141,90 @@ private function struct($node, $reset=FALSE, $parent=array())
foreach ($node as $subNode) {
$this->struct($subNode, FALSE, array('class' => $name));
}
} elseif ($node instanceof PHPParser_Node_Stmt_Property) {
} elseif ($node instanceof Stmt\Property) {
$kind = 'p';
$prop = $node->props[0];
$name = $prop->name;
$line = $prop->getLine();
$access = $this->getNodeAccess($node);
} elseif ($node instanceof PHPParser_Node_Stmt_ClassConst) {
} elseif ($node instanceof Stmt\ClassConst) {
$kind = 'd';
$cons = $node->consts[0];
$name = $cons->name;
$line = $cons->getLine();
} elseif ($node instanceof PHPParser_Node_Stmt_ClassMethod) {
} elseif ($node instanceof Stmt\ClassMethod) {
$kind = 'm';
$name = $node->name;
$line = $node->getLine();
$access = $this->getNodeAccess($node);
foreach ($node as $subNode) {
$this->struct($subNode, FALSE, array('method' => $name));
}
} elseif ($node instanceof PHPParser_Node_Stmt_If) {
} elseif ($node instanceof Stmt\If_) {
foreach ($node as $subNode) {
$this->struct($subNode);
}
} elseif ($node instanceof PHPParser_Node_Stmt_Const) {
} elseif ($node instanceof Stmt\Const_) {
$kind = 'd';
$cons = $node->consts[0];
$name = $cons->name;
$line = $node->getLine();
} elseif ($node instanceof PHPParser_Node_Stmt_Global) {
} elseif ($node instanceof Stmt\Global_) {
$kind = 'v';
$prop = $node->vars[0];
$name = $prop->name;
$line = $node->getLine();
} elseif ($node instanceof PHPParser_Node_Stmt_Static) {
} elseif ($node instanceof Stmt\Static_) {
//@todo
} elseif ($node instanceof PHPParser_Node_Stmt_Declare) {
} elseif ($node instanceof Stmt\Declare_) {
//@todo
} elseif ($node instanceof PHPParser_Node_Stmt_TryCatch) {
} elseif ($node instanceof Stmt\TryCatch) {
foreach ($node as $subNode) {
$this->struct($subNode);
}
} elseif ($node instanceof PHPParser_Node_Stmt_Function) {
} elseif ($node instanceof Stmt\Function_) {
$kind = 'f';
$name = $node->name;
$line = $node->getLine();
foreach ($node as $subNode) {
$this->struct($subNode, FALSE, array('function' => $name));
}
} elseif ($node instanceof PHPParser_Node_Stmt_Interface) {
} elseif ($node instanceof Stmt\Interface_) {
$kind = 'i';
$name = $node->name;
$line = $node->getLine();
foreach ($node as $subNode) {
$this->struct($subNode, FALSE, array('interface' => $name));
}
} elseif ($node instanceof PHPParser_Node_Stmt_Trait ) {
} elseif ($node instanceof Stmt\Trait_) {
$kind = 't';
$name = $node->name;
$line = $node->getLine();
foreach ($node as $subNode) {
$this->struct($subNode, FALSE, array('trait' => $name));
}
} elseif ($node instanceof PHPParser_Node_Stmt_Namespace) {
} elseif ($node instanceof Stmt\Namespace_) {
$kind = 'n';
$name = $node->name;
$line = $node->getLine();
foreach ($node as $subNode) {
$this->struct($subNode, FALSE, array('namespace' => $name));
}
} elseif ($node instanceof PHPParser_Node_Expr_Assign) {
} elseif ($node instanceof Expr\Assign) {
if (isset($node->var->name) && is_string($node->var->name)) {
$kind = 'v';
$node = $node->var;
$name = $node->name;
$line = $node->getLine();
}
} elseif ($node instanceof PHPParser_Node_Expr_AssignRef) {
} elseif ($node instanceof Expr\AssignRef) {
if (isset($node->var->name) && is_string($node->var->name)) {
$kind = 'v';
$node = $node->var;
$name = $node->name;
$line = $node->getLine();
}
} elseif ($node instanceof PHPParser_Node_Expr_FuncCall) {
} elseif ($node instanceof Expr\FuncCall) {
switch ($node->name) {
case 'define':
$kind = 'd';
Expand Down Expand Up @@ -274,7 +278,7 @@ private function render($structure)
if (empty($struct['name']) || empty($struct['line']) || empty($struct['kind']))
return;

if ($struct['name'] instanceof PHPParser_Node_Expr_Variable ){
if ($struct['name'] instanceof Expr\Variable) {
$str .= $struct['name']->name;
}else{
$str .= $struct['name'];
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "library",
"require": {
"php": ">=5.3",
"nikic/php-parser": "<1"
"nikic/php-parser": "^3.1"
},
"require-dev": {
"phpunit/phpunit": "~4"
Expand Down
Loading

0 comments on commit eedfec3

Please sign in to comment.