Skip to content
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

Updated PHP Parser from 1.4 to 3.1 #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Updated PHP Parser from 1.4 to 3.1
- Migrated from PHP Parser 1.4 to PHP Parser 2.1

Applied https://github.com/nikic/PHP-Parser/blob/v3.1.1/UPGRADE-2.0.md

Tried non breaking approach using PREFER_PHP5.
Everything works.

- Migrated from PHP Parser 2.1 to PHP Parser 3.1

Applied https://github.com/nikic/PHP-Parser/blob/v3.1.1/UPGRADE-3.0.md

Dropped the support for older versions of PHP.
Removed older PHP versions from CI
Reformatted code to CS
Harumaro committed Oct 4, 2017
commit bf314ad14dec10d5061634b0a190b4e15c6147c4
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@ cache:
- "$HOME/.composer/cache"

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -9,15 +9,15 @@
}
},
"require": {
"php": ">=5.3.3",
"php": ">=5.5",
"symfony/console": "~2.3 || ~3.0",
"symfony/finder": "~2.3 || ~3.0",
"pimple/pimple": "~3.0",
"nikic/php-parser": "~1.4",
"nikic/php-parser": "~3.1",
"bcncommerce/json-stream": "0.3.0"
},
"require-dev": {
"phpunit/phpunit": "4.7.*",
"phpunit/phpunit": "^4.8",
"mikey179/vfsStream": "~1.5",
"friendsofphp/php-cs-fixer": "~1.10"
},
4 changes: 2 additions & 2 deletions src/Infrastructure/ContainerBuilder.php
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
namespace Sstalle\php7cc\Infrastructure;

use PhpParser\NodeVisitor\NameResolver;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use Pimple\Container;
use Sstalle\php7cc\CLIResultPrinter;
use Sstalle\php7cc\ContextChecker;
@@ -167,7 +167,7 @@ public function buildContainer(OutputInterface $output, $intSize)
));
};
$container['parser'] = function ($c) {
return new Parser($c['lexer']);
return (new ParserFactory())->create(ParserFactory::PREFER_PHP5, $c['lexer']);
};

$this->addVisitors($container);
12 changes: 6 additions & 6 deletions src/Lexer/ExtendedLexer.php
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
namespace Sstalle\php7cc\Lexer;

use PhpParser\Lexer;
use PhpParser\Parser;
use PhpParser\Parser\Tokens;

class ExtendedLexer extends Lexer\Emulative
{
@@ -14,19 +14,19 @@ public function getNextToken(&$value = null, &$startAttributes = null, &$endAttr
{
$tokenId = parent::getNextToken($value, $startAttributes, $endAttributes);

if ($tokenId == Parser::T_CONSTANT_ENCAPSED_STRING // non-interpolated string
|| $tokenId == Parser::T_LNUMBER // integer
|| $tokenId == Parser::T_DNUMBER // floating point number
if ($tokenId == Tokens::T_CONSTANT_ENCAPSED_STRING // non-interpolated string
|| $tokenId == Tokens::T_LNUMBER // integer
|| $tokenId == Tokens::T_DNUMBER // floating point number
) {
// could also use $startAttributes, doesn't really matter here
$endAttributes['originalValue'] = $value;
}

if ($tokenId == Parser::T_CONSTANT_ENCAPSED_STRING) {
if ($tokenId == Tokens::T_CONSTANT_ENCAPSED_STRING) {
$endAttributes['isDoubleQuoted'] = $value[0] === '"';
}

if ($tokenId == Parser::T_END_HEREDOC) {
if ($tokenId == Tokens::T_END_HEREDOC) {
$endAttributes['isHereDoc'] = true;
}

7 changes: 6 additions & 1 deletion src/NodeVisitor/FuncGetArgsVisitor.php
Original file line number Diff line number Diff line change
@@ -134,8 +134,9 @@ private function getModifiedVariableNames(Node $node)
return $modifiedNames;

case $node instanceof Node\Stmt\Global_:
case $node instanceof Node\Expr\List_:
return $this->extractModifiedVariableNames($node->vars);
case $node instanceof Node\Expr\List_:
return $this->extractModifiedVariableNames($node->items);

case $node instanceof Node\Expr\Assign:
case $node instanceof Node\Expr\AssignOp:
@@ -265,6 +266,10 @@ private function extractModifiedVariableNames(array $nodes)
$variableNameNode = $node->var;
}

if ($node instanceof Node\Expr\ArrayItem) {
$variableNameNode = $node->value;
}

if (!($variableNameNode instanceof Node\Expr\Variable)) {
continue;
}
2 changes: 1 addition & 1 deletion src/NodeVisitor/ListVisitor.php
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ public function enterNode(Node $node)
{
if ($node instanceof Node\Expr\List_) {
$hasNonNullVar = false;
foreach ($node->vars as $var) {
foreach ($node->items as $var) {
if ($var !== null) {
$hasNonNullVar = true;
break;
5 changes: 5 additions & 0 deletions test/code/NodeStatementsRemoveTest.php
Original file line number Diff line number Diff line change
@@ -51,4 +51,9 @@ public function testRemoveSwitchCases()
class Node extends NodeAbstract
{
public $stmts;

public function getSubNodeNames()
{
return '';
}
}