Skip to content
This repository was archived by the owner on Jul 12, 2020. It is now read-only.

php7 support #73

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1c0b15c
Add support for renaming local variables inside functions
K-Phoen May 14, 2016
2aaabe1
Add a test for the local variable renaming inside functions
K-Phoen May 14, 2016
746d697
Fix undeclared variable usage
K-Phoen May 14, 2016
9306801
Allow to rename function and method arguments
K-Phoen May 14, 2016
b595ed0
Update vendors
K-Phoen May 14, 2016
867b96e
Use nikic/PHP-Parser ~2.0
K-Phoen May 14, 2016
3f4e7a8
Fix case in method call
K-Phoen May 14, 2016
ffb4867
Prefer single quotes when possible
K-Phoen May 14, 2016
d318e46
Remove useless semicolons
K-Phoen May 14, 2016
1a1f91e
Use short syntax for bits operation
K-Phoen May 14, 2016
ceee74a
Use assertCount in tests when possible
K-Phoen May 14, 2016
d89aef8
Update tests
K-Phoen May 14, 2016
33d81cf
Remove unused variables
K-Phoen May 14, 2016
8d94437
Remove unused imports
K-Phoen May 14, 2016
522a953
Remove unused attribute
K-Phoen May 14, 2016
c41c0b1
Fix undeclared variable usage
K-Phoen May 14, 2016
67cab17
Update travis-ci config
K-Phoen May 14, 2016
7e07066
PHP 7.0 should not be allowed to fail
K-Phoen May 14, 2016
eca98ae
Also test against HHVM
K-Phoen May 14, 2016
5696332
Disallow failures for HHVM
K-Phoen May 14, 2016
acc316f
Add rename property command
K-Phoen May 15, 2016
ae172a7
Add a few behat tests
K-Phoen May 15, 2016
286a0f1
Talk about the "Rename Class Property" refactor
K-Phoen May 16, 2016
e750c69
Switch to POPSuL fork of php-token-reflection
AJenbo Jun 4, 2017
8d49db4
Don't throw a fit when file doesn't contain a class
AJenbo Jun 4, 2017
ff01104
Switch to my branch of PHP-Token-Reflection
AJenbo Jun 4, 2017
bdc51b3
Hanvle nested array keys
AJenbo Jul 2, 2017
8c86834
Update README.md
AJenbo Jul 4, 2017
774b51e
Require php 5.5
AJenbo Jul 4, 2017
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
Prev Previous commit
Next Next commit
Update tests
  • Loading branch information
K-Phoen committed May 14, 2016
commit d89aef888105c919a8e81e12dc5ee2db9b295c05
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function enterAssignment(Node\Expr\Assign $node)
if ($node->var instanceof Node\Expr\Variable) {
$this->assignments[$node->var->name][] = $node->getLine();
$this->seenAssignmentVariables->attach($node->var);
} else if ($node instanceof Node\Expr\ArrayDimFetch) {
} else if ($node->var instanceof Node\Expr\ArrayDimFetch) {
// $foo[] = "baz" is both a read and a write access to $foo
$this->localVariables[$node->var->var->name][] = $node->getLine();
$this->assignments[$node->var->var->name][] = $node->getLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace QafooLabs\Refactoring\Adapters\PHPParser\Visitor;

use PHPParser_Parser;
use PHPParser_Lexer;
use PHPParser_NodeTraverser;
use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;

use QafooLabs\Refactoring\Domain\Model\LineRange;
use QafooLabs\Refactoring\Adapters\PHPParser\Visitor\NodeConnector;

class LineRangeStatementCollectorTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -25,14 +23,14 @@ public function givenNestedStatements_WhenCollecting_ThenOnlyCollectTopLevel()
$collectedStatements = $collector->getStatements();

$this->assertCount(1, $collectedStatements);
$this->assertInstanceOf('PHPParser_Node_Expr_MethodCall', $collectedStatements[0]);
$this->assertInstanceOf('PHPParser\Node\Expr\MethodCall', $collectedStatements[0]);
}

private function traverse($stmts, $visitor)
{
$this->connect($stmts);

$traverser = new PHPParser_NodeTraverser;
$traverser = new NodeTraverser();
$traverser->addVisitor(new NodeConnector);
$traverser->addVisitor($visitor);
$traverser->traverse($stmts);
Expand All @@ -42,7 +40,7 @@ private function traverse($stmts, $visitor)

private function connect($stmts)
{
$traverser = new PHPParser_NodeTraverser;
$traverser = new NodeTraverser();
$traverser->addVisitor(new NodeConnector);
return $traverser->traverse($stmts);
}
Expand All @@ -58,7 +56,9 @@ private function statements($code)
$code = "<?php\n" . $code;
}

$parser = new PHPParser_Parser(new PHPParser_Lexer());
$parserFactory = new ParserFactory();
$parser = $parserFactory->create(ParserFactory::PREFER_PHP7);

return $parser->parse($code);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace QafooLabs\Refactoring\Adapters\PHPParser\Visitor;

use PhpParser\Node\Expr;
use PhpParser\NodeTraverser;

class LocalVariableClassifierTest extends \PHPUnit_Framework_TestCase
{
/**
Expand All @@ -10,7 +13,7 @@ class LocalVariableClassifierTest extends \PHPUnit_Framework_TestCase
public function givenVariable_WhenClassification_ThenLocalVariableFound()
{
$classifier = new LocalVariableClassifier();
$variable = new \PHPParser_Node_Expr_Variable('foo');
$variable = new Expr\Variable('foo');

$classifier->enterNode($variable);

Expand All @@ -23,9 +26,9 @@ public function givenVariable_WhenClassification_ThenLocalVariableFound()
public function givenAssignment_WhenClassification_ThenAssignmentFound()
{
$classifier = new LocalVariableClassifier();
$assign = new \PHPParser_Node_Expr_Assign(
new \PHPParser_Node_Expr_Variable('foo'),
new \PHPParser_Node_Expr_Variable('bar')
$assign = new Expr\Assign(
new Expr\Variable('foo'),
new Expr\Variable('bar')
);

$classifier->enterNode($assign);
Expand All @@ -39,12 +42,12 @@ public function givenAssignment_WhenClassification_ThenAssignmentFound()
public function givenAssignmentAndReadOfSameVariable_WhenClassification_ThenFindBoth()
{
$classifier = new LocalVariableClassifier();
$assign = new \PHPParser_Node_Expr_Assign(
new \PHPParser_Node_Expr_Variable('foo'),
new \PHPParser_Node_Expr_Variable('foo')
$assign = new Expr\Assign(
new Expr\Variable('foo'),
new Expr\Variable('foo')
);

$traverser = new \PHPParser_NodeTraverser;
$traverser = new NodeTraverser();
$traverser->addVisitor($classifier);
$traverser->traverse(array($assign));

Expand All @@ -58,7 +61,7 @@ public function givenAssignmentAndReadOfSameVariable_WhenClassification_ThenFind
public function givenThisVariable_WhenClassification_ThenNoLocalVariables()
{
$classifier = new LocalVariableClassifier();
$variable = new \PHPParser_Node_Expr_Variable('this');
$variable = new Expr\Variable('this');

$classifier->enterNode($variable);

Expand All @@ -71,7 +74,7 @@ public function givenThisVariable_WhenClassification_ThenNoLocalVariables()
public function givenParam_WhenClassification_FindAsAssignment()
{
$classifier = new LocalVariableClassifier();
$variable = new \PHPParser_Node_Param('foo');
$variable = new \PhpParser\Node\Param('foo');

$classifier->enterNode($variable);

Expand All @@ -86,11 +89,11 @@ public function givenArrayDimFetchASsignment_WhenClassification_FindAsAssignment
{
$classifier = new LocalVariableClassifier();

$assign = new \PHPParser_Node_Expr_Assign(
new \PHPParser_Node_Expr_ArrayDimFetch(
new \PHPParser_Node_Expr_Variable('foo')
$assign = new Expr\Assign(
new Expr\ArrayDimFetch(
new Expr\Variable('foo')
),
new \PHPParser_Node_Expr_Variable('bar')
new Expr\Variable('bar')
);

$classifier->enterNode($assign);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
use QafooLabs\Refactoring\Domain\Model\Variable;
use QafooLabs\Refactoring\Domain\Model\DefinedVariables;

use QafooLabs\Refactoring\Adapters\PHPParser\ParserVariableScanner;
use QafooLabs\Refactoring\Adapters\TokenReflection\StaticCodeAnalysis;
use QafooLabs\Refactoring\Adapters\Patches\PatchEditor;

class RenameLocalVariableTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
Expand All @@ -20,7 +16,7 @@ public function setUp()
$this->editor = \Phake::mock('QafooLabs\Refactoring\Domain\Services\Editor');
$this->refactoring = new RenameLocalVariable($this->scanner, $this->codeAnalysis, $this->editor);

\Phake::when($this->codeAnalysis)->isInsideMethod(\Phake::anyParameters())->thenReturn(true);
\Phake::when($this->codeAnalysis)->isLocalScope(\Phake::anyParameters())->thenReturn(true);
}

public function testRenameLocalVariable()
Expand Down