Skip to content
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1,385 changes: 971 additions & 414 deletions composer.lock

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions src/phpDocumentor/Reflection/BaseReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Exception;
use InvalidArgumentException;
use phpDocumentor\Event\Dispatcher;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Context;
use phpDocumentor\Reflection\DocBlock\Location;
use phpDocumentor\Reflection\Event\PostDocBlockExtractionEvent;
Expand Down Expand Up @@ -167,9 +166,19 @@ public function getName()
*/
public function getShortName()
{
return isset($this->node->name)
? $this->node->name
: (string) $this->node;
if ( isset($this->node->name) ) {
return $this->node->name;
}

if (interface_exists('\Stringable') && $this->node instanceof \Stringable){
return (string) $this->node;
} elseif (method_exists( $this->node, '__toString')) {
return (string) $this->node;
}

if ($this->node instanceof \PhpParser\Node\Stmt\Class_ && $this->node->isAnonymous()) {
return 'class@anonymous';
}
}

/**
Expand Down Expand Up @@ -297,7 +306,7 @@ public function getDefaultPackageName()
* @return string
*/
protected function getRepresentationOfValue(
\PhpParser\Node\Expr $value = null
?\PhpParser\Node\Expr $value = null
) {
if (null === $value) {
return '';
Expand Down
4 changes: 2 additions & 2 deletions src/phpDocumentor/Reflection/Event/ExportDocBlockTagEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getObject()
*
* @return ExportDocBlockTagEvent
*/
public function setObject(Tag $object = null)
public function setObject(?Tag $object = null)
{
$this->object = $object;

Expand All @@ -46,7 +46,7 @@ public function setObject(Tag $object = null)
*
* @return ExportDocBlockTagEvent
*/
public function setXml(DOMNode $xml = null)
public function setXml(?DOMNode $xml = null)
{
$this->xml = $xml;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PostDocBlockExtractionEvent extends EventAbstract
*
* @return $this
*/
public function setDocblock(DocBlock $docblock = null)
public function setDocblock(?DocBlock $docblock = null)
{
$this->docblock = $docblock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
16 changes: 16 additions & 0 deletions src/phpDocumentor/Reflection/IncludeReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 1 addition & 2 deletions src/phpDocumentor/Reflection/PrettyPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace phpDocumentor\Reflection;

use PhpParser\Node\Scalar\String_;
use PhpParser\PrettyPrinter\Standard;

/**
* Custom PrettyPrinter for phpDocumentor.
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/phpDocumentor/Reflection/Traverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/phpDocumentor/Reflection/BaseReflectorMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BaseReflectorMock extends BaseReflector
* @return string
*/
public function getRepresentationOfValueMock(
Expr $value = null
?Expr $value = null
) {
return parent::getRepresentationOfValue($value);
}
Expand Down