Skip to content

Add namespaced classes for the PHP Parser #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/class-file-reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class File_Reflector extends FileReflector {
/**
* Last DocBlock associated with a non-documentable element.
*
* @var \PHPParser_Comment_Doc
* @var \PhpParser\Comment\Doc
*/
protected $last_doc = null;

Expand All @@ -61,9 +61,9 @@ class File_Reflector extends FileReflector {
* Finally, we pick up any docblocks for nodes that usually aren't documentable,
* so they can be assigned to the hooks to which they may belong.
*
* @param \PHPParser_Node $node
* @param \PhpParser\Node $node
*/
public function enterNode( \PHPParser_Node $node ) {
public function enterNode( \PhpParser\Node $node ) {
parent::enterNode( $node );

switch ( $node->getType() ) {
Expand Down Expand Up @@ -137,9 +137,9 @@ public function enterNode( \PHPParser_Node $node ) {
* We can now access the function/method reflectors, so we can assign any queued
* hooks to them. The reflector for a node isn't created until the node is left.
*
* @param \PHPParser_Node $node
* @param \PhpParser\Node $node
*/
public function leaveNode( \PHPParser_Node $node ) {
public function leaveNode( \PhpParser\Node $node ) {

parent::leaveNode( $node );

Expand Down Expand Up @@ -189,11 +189,11 @@ public function leaveNode( \PHPParser_Node $node ) {
}

/**
* @param \PHPParser_Node $node
* @param \PhpParser\Node $node
*
* @return bool
*/
protected function isFilter( \PHPParser_Node $node ) {
protected function isFilter( \PhpParser\Node $node ) {
// Ignore variable functions
if ( 'Name' !== $node->name->getType() ) {
return false;
Expand Down Expand Up @@ -221,13 +221,13 @@ protected function getLocation() {
}

/**
* @param \PHPParser_Node $node
* @param \PhpParser\Node $node
*
* @return bool
*/
protected function isNodeDocumentable( \PHPParser_Node $node ) {
protected function isNodeDocumentable( \PhpParser\Node $node ) {
return parent::isNodeDocumentable( $node )
|| ( $node instanceof \PHPParser_Node_Expr_FuncCall
|| ( $node instanceof \PhpParser\Node\Expr\FuncCall
&& $this->isFilter( $node ) );
}
}
12 changes: 6 additions & 6 deletions lib/class-function-call-reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ public function getName() {

$shortName = $this->getShortName();

if ( is_a( $shortName, 'PHPParser_Node_Name_FullyQualified' ) ) {
if ( is_a( $shortName, 'PhpParser\Node\Name\FullyQualified' ) ) {
return '\\' . (string) $shortName;
}

if ( is_a( $shortName, 'PHPParser_Node_Name' ) ) {
if ( is_a( $shortName, 'PhpParser\Node\Name' ) ) {
return (string) $shortName;
}

/** @var \PHPParser_Node_Expr_ArrayDimFetch $shortName */
if ( is_a( $shortName, 'PHPParser_Node_Expr_ArrayDimFetch' ) ) {
/** @var \PhpParser\Node\Expr\ArrayDimFetch $shortName */
if ( is_a( $shortName, 'PhpParser\Node\Expr\ArrayDimFetch' ) ) {
$var = $shortName->var->name;
$dim = $shortName->dim->name->parts[0];

return "\${$var}[{$dim}]";
}

/** @var \PHPParser_Node_Expr_Variable $shortName */
if ( is_a( $shortName, 'PHPParser_Node_Expr_Variable' ) ) {
/** @var \PhpParser\Node\Expr\Variable $shortName */
if ( is_a( $shortName, 'PhpParser\Node\Expr\Variable' ) ) {
return $shortName->name;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/class-hook-reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace WP_Parser;

use phpDocumentor\Reflection\BaseReflector;
use PHPParser_PrettyPrinter_Default;
use \PhpParser\PrettyPrinter\Standard;

/**
* Custom reflector for WordPress hooks.
Expand All @@ -14,7 +14,7 @@ class Hook_Reflector extends BaseReflector {
* @return string
*/
public function getName() {
$printer = new PHPParser_PrettyPrinter_Default;
$printer = new \PhpParser\PrettyPrinter\Standard;
return $this->cleanupName( $printer->prettyPrintExpr( $this->node->args[0]->value ) );
}

Expand Down
10 changes: 5 additions & 5 deletions lib/class-method-call-reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ public function getName() {
$caller = $this->node->var;
}

if ( $caller instanceof \PHPParser_Node_Expr ) {
if ( $caller instanceof \PhpParser\Node\Expr ) {
$printer = new Pretty_Printer;
$caller = $printer->prettyPrintExpr( $caller );
} elseif ( $caller instanceof \PHPParser_Node_Name_FullyQualified ) {
} elseif ( $caller instanceof \PhpParser\Node\Name\FullyQualified ) {
$caller = '\\' . $caller->toString();
} elseif ( $caller instanceof \PHPParser_Node_Name ) {
} elseif ( $caller instanceof \PhpParser\Node\Name ) {
$caller = $caller->toString();
}

$caller = $this->_resolveName( $caller );

// If the caller is a function, convert it to the function name
if ( is_a( $caller, 'PHPParser_Node_Expr_FuncCall' ) ) {
if ( is_a( $caller, 'PhpParser\Node\Expr\FuncCall' ) ) {

// Add parentheses to signify this is a function call
/** @var \PHPParser_Node_Expr_FuncCall $caller */
/** @var \PhpParser\Node\Expr\FuncCall $caller */
$caller = implode( '\\', $caller->name->parts ) . '()';
}

Expand Down
10 changes: 5 additions & 5 deletions lib/class-pretty-printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace WP_Parser;

use PHPParser_Node_Arg;
use PHPParser_PrettyPrinter_Default;
use PhpParser\Node\Arg;
use PhpParser\PrettyPrinter\Standard;

/**
* Extends default printer for arguments.
*/
class Pretty_Printer extends PHPParser_PrettyPrinter_Default {
class Pretty_Printer extends \PhpParser\PrettyPrinter\Standard {
/**
* Pretty prints an argument.
*
* @param PHPParser_Node_Arg $node Expression argument
* @param PhpParser\Node\Arg $node Expression argument
*
* @return string Pretty printed argument
*/
public function prettyPrintArg( PHPParser_Node_Arg $node ) {
public function prettyPrintArg( \PhpParser\Node\Arg $node ) {
return str_replace( "\n" . $this->noIndentToken, "\n", $this->p( $node ) );
}
}
2 changes: 1 addition & 1 deletion lib/class-static-method-call-reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Static_Method_Call_Reflector extends Method_Call_Reflector {
*/
public function getName() {
$class = $this->node->class;
$prefix = ( is_a( $class, 'PHPParser_Node_Name_FullyQualified' ) ) ? '\\' : '';
$prefix = ( is_a( $class, 'PhpParser\Node\Name\FullyQualified' ) ) ? '\\' : '';
$class = $prefix . $this->_resolveName( implode( '\\', $class->parts ) );

return array( $class, $this->getShortName() );
Expand Down