Skip to content

Commit

Permalink
Upgrade to PHP-Parser 4 (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored and theofidry committed May 28, 2018
1 parent 36378fb commit 91fae9c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

"require": {
"php": "^7.1",
"nikic/php-parser": "^3.0",
"nikic/php-parser": "^4.0",
"ocramius/package-versions": "^1.1",
"roave/better-reflection": "^2.0",
"roave/better-reflection": "^3.0",
"symfony/console": "^3.2 || ^4.0",
"symfony/filesystem": "^3.2 || ^4.0",
"symfony/finder": "^3.2 || ^4.0"
Expand Down
45 changes: 23 additions & 22 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/PhpParser/NodeTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(string $prefix)
/**
* @inheritdoc
*/
public function traverse(array $nodes)
public function traverse(array $nodes): array
{
$nodes = $this->wrapInNamespace($nodes);
$nodes = $this->replaceGroupUseStatements($nodes);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpParser/NodeVisitor/Collection/UseStmtCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function findStatementForNode(?Name $namespaceName, Name $node): ?Name
foreach ($useStatements as $use_) {
foreach ($use_->uses as $useStatement) {
if ($useStatement instanceof UseUse) {
if ($name === strtolower($useStatement->alias)) {
if ($name === $useStatement->getAlias()->toLowerString()) {
if ($parentNode instanceof FuncCall && 1 === count($node->parts)) {
if (Use_::TYPE_FUNCTION === $use_->type) {
return $useStatement->name;
Expand Down
11 changes: 6 additions & 5 deletions src/PhpParser/NodeVisitor/WhitelistedClassAppender.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\NodeVisitorAbstract;
Expand Down Expand Up @@ -89,21 +90,21 @@ private function appendToNamespaceStmt(Namespace_ $namespace): Namespace_
}

/** @var Class_ $stmt */
$name = FullyQualified::concat($namespace->name, $stmt->name);
$name = FullyQualified::concat((string) $namespace->name, (string) $stmt->name);
$originalName = $name->slice(1);

if (false === in_array((string) $originalName, $this->whitelist, true)) {
continue;
}

$newStmts[] = new FuncCall(
$newStmts[] = new Expression(new FuncCall(
new Name('class_alias'),
[
new Arg(
new String_($name)
new String_((string) $name)
),
new Arg(
new String_($originalName)
new String_((string) $originalName)
),
new Arg(
new ConstFetch(
Expand All @@ -112,7 +113,7 @@ private function appendToNamespaceStmt(Namespace_ $namespace): Namespace_
),
],
['whitelist_class_alias' => true]
);
));
}

$namespace->stmts = $newStmts;
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpParser/FakeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class FakeParser implements Parser
/**
* @inheritdoc
*/
public function parse($code, ErrorHandler $errorHandler = null)
public function parse(string $code, ErrorHandler $errorHandler = null)
{
throw new \LogicException();
}
Expand Down

0 comments on commit 91fae9c

Please sign in to comment.