diff --git a/composer.json b/composer.json index b4445922..c3e34cd3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": ">=5.3.3", "psr/log": "~1.0", - "nikic/php-parser": "^1.0", + "nikic/php-parser": "^3.0", "phpdocumentor/reflection-docblock": "~2.0" }, "suggests": { @@ -25,7 +25,8 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.0.x-dev", + "dev-wp": "v3.0.2-dmsnell" } } } diff --git a/src/phpDocumentor/Reflection/BaseReflector.php b/src/phpDocumentor/Reflection/BaseReflector.php index 543da1cd..b62d24e0 100644 --- a/src/phpDocumentor/Reflection/BaseReflector.php +++ b/src/phpDocumentor/Reflection/BaseReflector.php @@ -169,7 +169,7 @@ public function getShortName() { return isset($this->node->name) ? $this->node->name - : (string) $this->node; + : '(anonymous)'; } /** diff --git a/src/phpDocumentor/Reflection/FunctionReflector/ArgumentReflector.php b/src/phpDocumentor/Reflection/FunctionReflector/ArgumentReflector.php index 8b338711..0f1bfcba 100644 --- a/src/phpDocumentor/Reflection/FunctionReflector/ArgumentReflector.php +++ b/src/phpDocumentor/Reflection/FunctionReflector/ArgumentReflector.php @@ -52,6 +52,10 @@ public function getDefault() */ public function getType() { + if ( $this->node->type instanceof \PhpParser\Node\NullableType ) { + return "?{$this->node->type->type}"; + } + $type = (string) $this->node->type; // in case of the callable of array keyword; do not prefix with a \ diff --git a/src/phpDocumentor/Reflection/IncludeReflector.php b/src/phpDocumentor/Reflection/IncludeReflector.php index 8b2eb5ca..4360366d 100644 --- a/src/phpDocumentor/Reflection/IncludeReflector.php +++ b/src/phpDocumentor/Reflection/IncludeReflector.php @@ -53,6 +53,22 @@ public function getType() public function getShortName() { + if ( ! isset( $this->node->expr->value ) ) { + $name = []; + foreach ( $this->node->expr->getSubNodeNames() as $part ) { + $thing = $this->node->expr->{$part}; + + $name[] = ( is_object( $thing ) && method_exists( $thing, 'getName' ) ) + ? $thing->getName() + : ( ( is_array( $thing ) + ? array_key_exists( 'value', $thing ) + : property_exists( $thing, 'value' ) + ) + ? $thing->value + : '(unknown)' ); + } + $name = implode( ' . ', $name ); + } return (string) $this->node->expr->value; } } diff --git a/src/phpDocumentor/Reflection/PrettyPrinter.php b/src/phpDocumentor/Reflection/PrettyPrinter.php index 0d9d0704..c99f456f 100644 --- a/src/phpDocumentor/Reflection/PrettyPrinter.php +++ b/src/phpDocumentor/Reflection/PrettyPrinter.php @@ -13,7 +13,6 @@ namespace phpDocumentor\Reflection; use PhpParser\Node\Scalar\String_; -use PhpParser\PrettyPrinter\Standard; /** * Custom PrettyPrinter for phpDocumentor. @@ -28,7 +27,7 @@ * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ -class PrettyPrinter extends Standard +class PrettyPrinter extends \PhpParser\PrettyPrinter\Standard { /** * Converts the string into it's original representation without converting diff --git a/src/phpDocumentor/Reflection/Traverser.php b/src/phpDocumentor/Reflection/Traverser.php index 31c3890b..abcd8bbe 100644 --- a/src/phpDocumentor/Reflection/Traverser.php +++ b/src/phpDocumentor/Reflection/Traverser.php @@ -15,6 +15,7 @@ use PhpParser\Error; use PhpParser\NodeVisitor\NameResolver; use PhpParser\Parser; +use PhpParser\ParserFactory; use PhpParser\NodeTraverser; use PhpParser\NodeVisitor; use PhpParser\NodeVisitorAbstract; @@ -78,7 +79,7 @@ public function addVisitor(\PhpParser\NodeVisitor $visitor) */ protected function createParser() { - return new Parser(new Lexer()); + return (new ParserFactory)->create(ParserFactory::PREFER_PHP7); } /** @@ -88,7 +89,7 @@ protected function createParser() */ protected function createTraverser() { - $node_traverser = new NodeTraverser(); + $node_traverser = new NodeTraverser(true); $node_traverser->addVisitor(new NameResolver()); foreach ($this->visitors as $visitor) {