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
Prefer single quotes when possible
  • Loading branch information
K-Phoen committed May 14, 2016
commit ffb48679f91f88a53716e02bb70dd84b432ea55b
2 changes: 1 addition & 1 deletion src/bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php

if ((!@include __DIR__ . '/../../../../autoload.php') && (!@include __DIR__ . '/../../vendor/autoload.php')) {
die("You must set up the project dependencies, run composer install");
die('You must set up the project dependencies, run composer install');
}

use QafooLabs\Refactoring\Adapters\Symfony\Compiler;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/refactor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php

if ((!@include __DIR__ . '/../../../../autoload.php') && (!@include __DIR__ . '/../../vendor/autoload.php')) {
die("You must set up the project dependencies, run composer install");
die('You must set up the project dependencies, run composer install');
}

use QafooLabs\Refactoring\Adapters\Symfony\CliApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function findNames(File $file)
try {
$stmts = $parser->parse($file->getCode());
} catch (\PHPParser\Error $e) {
throw new \RuntimeException("Error parsing " . $file->getRelativePath() .": " . $e->getMessage(), 0, $e);
throw new \RuntimeException('Error parsing ' . $file->getRelativePath() . ': ' . $e->getMessage(), 0, $e);
}

$traverser->addVisitor($collector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function scanForVariables(File $file, LineRange $range)
$selectedStatements = $collector->getStatements();

if ( ! $selectedStatements) {
throw new \RuntimeException("No statements found in line range.");
throw new \RuntimeException('No statements found in line range.');
}

$localVariableClassifier = new LocalVariableClassifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private function enterAssignment(Node\Expr\Assign $node)

private function enterVariableNode(Node\Expr\Variable $node)
{
if ($node->name === "this" || $this->seenAssignmentVariables->contains($node)) {
if ($node->name === 'this' || $this->seenAssignmentVariables->contains($node)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getMethodEndLine(File $file, LineRange $range)
$method = $this->findMatchingMethod($file, $range);

if ($method === null) {
throw new \InvalidArgumentException("Could not find method end line.");
throw new \InvalidArgumentException('Could not find method end line.');
}

return $method->getEndLine();
Expand All @@ -56,7 +56,7 @@ public function getMethodStartLine(File $file, LineRange $range)
$method = $this->findMatchingMethod($file, $range);

if ($method === null) {
throw new \InvalidArgumentException("Could not find method start line.");
throw new \InvalidArgumentException('Could not find method start line.');
}

return $method->getStartLine();
Expand All @@ -67,7 +67,7 @@ public function getFunctionEndLine(File $file, LineRange $range)
$function = $this->findMatchingFunction($file, $range);

if ($function === null) {
throw new \InvalidArgumentException("Could not find function end line.");
throw new \InvalidArgumentException('Could not find function end line.');
}

return $function->getEndLine();
Expand All @@ -78,7 +78,7 @@ public function getFunctionStartLine(File $file, LineRange $range)
$function = $this->findMatchingFunction($file, $range);

if ($function === null) {
throw new \InvalidArgumentException("Could not find function start line.");
throw new \InvalidArgumentException('Could not find function start line.');
}

return $function->getStartLine();
Expand All @@ -105,7 +105,7 @@ public function getLineOfLastPropertyDefinedInScope(File $file, $lastLine)
}
}

throw new \InvalidArgumentException("Could not find method start line.");
throw new \InvalidArgumentException('Could not find method start line.');
}

public function isInsideMethod(File $file, LineRange $range)
Expand Down
2 changes: 1 addition & 1 deletion src/main/QafooLabs/Refactoring/Domain/Model/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function findAllPhpFilesRecursivly()
RecursiveIteratorIterator::LEAVES_ONLY
),
function (SplFileInfo $file) {
return substr($file->getFilename(), -4) === ".php";
return substr($file->getFilename(), -4) === '.php';
}
),
function ($file) use ($workingDirectory) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/QafooLabs/Refactoring/Domain/Model/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class File
public static function createFromPath($path, $workingDirectory)
{
if ( ! file_exists($path) || ! is_file($path)) {
throw new \InvalidArgumentException("Not a valid file: " . $path);
throw new \InvalidArgumentException('Not a valid file: ' . $path);
}

$code = file_get_contents($path);
$workingDirectory = rtrim($workingDirectory, '/\\');
$relativePath = ltrim(str_replace($workingDirectory, "", $path), "/\\");
$relativePath = ltrim(str_replace($workingDirectory, '', $path), "/\\");

// converted mixed, wrapped, absolute paths on windows
if (DIRECTORY_SEPARATOR === '\\' && strpos($relativePath, '://') !== FALSE) {
Expand Down Expand Up @@ -92,7 +92,7 @@ public function extractPsr0ClassName()

private function parseFileForPsr0ClassShortName()
{
return str_replace(".php", "", $this->getBaseName());
return str_replace('.php', '', $this->getBaseName());
}

private function parseFileForPsr0NamespaceName()
Expand All @@ -119,7 +119,7 @@ private function parseFileForPsr0NamespaceName()

array_pop($namespace);

return str_replace(".php", "", implode("\\", $namespace));
return str_replace('.php', '', implode("\\", $namespace));
}

private function startsWithLowerCase($string)
Expand Down
2 changes: 1 addition & 1 deletion src/main/QafooLabs/Refactoring/Domain/Model/LineRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static public function fromLines($start, $end)
*/
static public function fromString($range)
{
list($start, $end) = explode("-", $range);
list($start, $end) = explode('-', $range);

return self::fromLines($start, $end);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function change($flags)
}

if ( ! in_array(($flags & $visibility), $allowedVisibilities)) {
throw new \InvalidArgumentException("Mix of visibilities is not allowed.");
throw new \InvalidArgumentException('Mix of visibilities is not allowed.');
}

return $flags;
Expand Down
2 changes: 1 addition & 1 deletion src/main/QafooLabs/Refactoring/Domain/Model/PhpName.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function __toString()

public function hashCode()
{
return "1373136332" . $this->fullyQualifiedName . $this->relativeName;
return '1373136332' . $this->fullyQualifiedName . $this->relativeName;
}

public function fullyQualified()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public function change(PhpName $name)

public function hashCode()
{
return "1373136290" . $this->fromName->hashCode() . $this->toName->hashCode();
return '1373136290' . $this->fromName->hashCode() . $this->toName->hashCode();
}
}
4 changes: 2 additions & 2 deletions src/main/QafooLabs/Refactoring/Utils/ValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ abstract class ValueObject
{
final public function __set($name, $value)
{
throw new \BadmethodCallException("Cannot set values on a value object.");
throw new \BadmethodCallException('Cannot set values on a value object.');
}

public function __get($name)
{
if ( ! isset($this->$name)) {
throw new \RuntimeException(sprintf("Variable %s does not exist on %s.", $name, get_class($this)));
throw new \RuntimeException(sprintf('Variable %s does not exist on %s.', $name, get_class($this)));
}

return $this->$name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testFindNames()

public function testRegressionFindNamesDetectsFQCNCorrectly()
{
$file = new File("Fqcn.php", <<<'PHP'
$file = new File('Fqcn.php', <<<'PHP'
<?php

namespace Bar;
Expand Down Expand Up @@ -69,7 +69,7 @@ function ($occurance) {

public function testFindNamesFindsParentForPhpNameInSingleLineUseStatement()
{
$file = new File("Fqcn.php", <<<'PHP'
$file = new File('Fqcn.php', <<<'PHP'
<?php

use Bar\Qux\Adapter;
Expand Down Expand Up @@ -97,7 +97,7 @@ public function testFindNamesFindsParentForPhpNameInSingleLineUseStatement()

public function testFindNamesFindsParentForPhpNameInMultiLineUseStatement()
{
$file = new File("Fqcn.php", <<<'PHP'
$file = new File('Fqcn.php', <<<'PHP'
<?php

use Bar\Qux\Adapter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function givenNestedStatements_WhenCollecting_ThenOnlyCollectTopLevel()
{
$stmts = $this->statements('$this->foo(bar(baz()));');

$collector = new LineRangeStatementCollector($this->range("2-2"));
$collector = new LineRangeStatementCollector($this->range('2-2'));

$this->traverse($stmts, $collector);

Expand Down Expand Up @@ -54,7 +54,7 @@ private function range($range)

private function statements($code)
{
if (strpos($code, "<?php") === false) {
if (strpos($code, '<?php') === false) {
$code = "<?php\n" . $code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LocalVariableClassifierTest extends \PHPUnit_Framework_TestCase
public function givenVariable_WhenClassification_ThenLocalVariableFound()
{
$classifier = new LocalVariableClassifier();
$variable = new \PHPParser_Node_Expr_Variable("foo");
$variable = new \PHPParser_Node_Expr_Variable('foo');

$classifier->enterNode($variable);

Expand All @@ -24,8 +24,8 @@ 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")
new \PHPParser_Node_Expr_Variable('foo'),
new \PHPParser_Node_Expr_Variable('bar')
);

$classifier->enterNode($assign);
Expand All @@ -40,8 +40,8 @@ public function givenAssignmentAndReadOfSameVariable_WhenClassification_ThenFind
{
$classifier = new LocalVariableClassifier();
$assign = new \PHPParser_Node_Expr_Assign(
new \PHPParser_Node_Expr_Variable("foo"),
new \PHPParser_Node_Expr_Variable("foo")
new \PHPParser_Node_Expr_Variable('foo'),
new \PHPParser_Node_Expr_Variable('foo')
);

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

$classifier->enterNode($variable);

Expand All @@ -71,7 +71,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 @@ -88,9 +88,9 @@ public function givenArrayDimFetchASsignment_WhenClassification_FindAsAssignment

$assign = new \PHPParser_Node_Expr_Assign(
new \PHPParser_Node_Expr_ArrayDimFetch(
new \PHPParser_Node_Expr_Variable("foo")
new \PHPParser_Node_Expr_Variable('foo')
),
new \PHPParser_Node_Expr_Variable("bar")
new \PHPParser_Node_Expr_Variable('bar')
);

$classifier->enterNode($assign);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testRenameLocalVariable()
\Phake::when($this->editor)->openBuffer(\Phake::anyParameters())->thenReturn($buffer);
\Phake::when($this->codeAnalysis)->findMethodRange(\Phake::anyParameters())->thenReturn(LineRange::fromSingleLine(1));

$patch = $this->refactoring->refactor(new File("foo.php", <<<'PHP'
$patch = $this->refactoring->refactor(new File('foo.php', <<<'PHP'
<?php
class Foo
{
Expand All @@ -53,7 +53,7 @@ public function testRenameNonLocalVariable_ThrowsException()
$this->setExpectedException('QafooLabs\Refactoring\Domain\Model\RefactoringException', 'Given variable "$this->foo" is required to be local to the current method.');

$this->refactoring->refactor(
new File("foo.php", ''), 6,
new File('foo.php', ''), 6,
new Variable('$this->foo'),
new Variable('$foo')
);
Expand All @@ -64,7 +64,7 @@ public function testRenameIntoNonLocalVariable_ThrowsException()
$this->setExpectedException('QafooLabs\Refactoring\Domain\Model\RefactoringException', 'Given variable "$this->foo" is required to be local to the current method.');

$this->refactoring->refactor(
new File("foo.php", ''), 6,
new File('foo.php', ''), 6,
new Variable('$foo'),
new Variable('$this->foo')
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function setUp()
*/
public function testRefactorSimpleMethod()
{
$patch = $this->refactoring->refactor(new File("foo.php", <<<'PHP'
$patch = $this->refactoring->refactor(new File('foo.php', <<<'PHP'
<?php
class Foo
{
Expand All @@ -38,7 +38,7 @@ public function main()
}
}
PHP
), LineRange::fromString("6-6"), "helloWorld");
), LineRange::fromString('6-6'), 'helloWorld');


\Phake::verify($this->applyCommand)->apply(<<<'CODE'
Expand Down Expand Up @@ -69,7 +69,7 @@ public function testVariableUsedBeforeAndAfterExtractedSlice()
{
$this->markTestIncomplete('Failing over some invisible whitespace issue?');

$patch = $this->refactoring->refactor(new File("foo.php", <<<'PHP'
$patch = $this->refactoring->refactor(new File('foo.php', <<<'PHP'
<?php
class Foo
{
Expand All @@ -85,7 +85,7 @@ public function main()
}
}
PHP
), LineRange::fromString("9-10"), "extract");
), LineRange::fromString('9-10'), 'extract');


\Phake::verify($this->applyCommand)->apply(<<<'CODE'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testCreateFromSingleLine()

public function testCreateFromString()
{
$range = LineRange::fromString("1-4");
$range = LineRange::fromString('1-4');

$this->assertEquals(1, $range->getStart());
$this->assertEquals(4, $range->getEnd());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MethodSignatureTest extends \PHPUnit_Framework_TestCase
*/
public function whenCreateMethodSignatureWithDefaults_ThenIsPrivateAndNotStatic()
{
$method = new MethodSignature("foo");
$method = new MethodSignature('foo');

$this->assertTrue($method->isPrivate());
$this->assertFalse($method->isStatic());
Expand All @@ -20,17 +20,17 @@ public function whenCreateMethodSignatureWithDefaults_ThenIsPrivateAndNotStatic(
*/
public function whenCreateMethodSignatureWithInvalidVisibility_ThenThrowException()
{
$this->setExpectedException("InvalidArgumentException");
$this->setExpectedException('InvalidArgumentException');

$method = new MethodSignature("foo", MethodSignature::IS_PRIVATE | MethodSignature::IS_PUBLIC);
$method = new MethodSignature('foo', MethodSignature::IS_PRIVATE | MethodSignature::IS_PUBLIC);
}

/**
* @test
*/
public function whenCreateMethodSignatureWithStaticOnly_ThenAssumePrivateVisibility()
{
$method = new MethodSignature("foo", MethodSignature::IS_STATIC);
$method = new MethodSignature('foo', MethodSignature::IS_STATIC);

$this->assertTrue($method->isPrivate());
$this->assertTrue($method->isStatic());
Expand Down
Loading