-
-
Notifications
You must be signed in to change notification settings - Fork 708
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
Add RemoveFuncCallArgRector, ClearReturnNewByReferenceRector, RemoveIniGetSetFuncCallRector, ReplaceHttpServerVarsByServerRector #3455
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d28e599
Add RemoveFuncCallArgRector
TomasVotruba ae5ee7d
[PHP 5.3] Add ClearReturnNewByReferenceRector
TomasVotruba 2013528
Add RemoveIniGetSetFuncCallRector
TomasVotruba bf8641c
update docs
TomasVotruba de03278
[PHP 5.3] Add ReplaceHttpServerVarsByServerRector
TomasVotruba 01efa94
update docs
TomasVotruba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
services: | ||
Rector\Php52\Rector\Property\VarToPublicPropertyRector: null | ||
Rector\Php52\Rector\Switch_\ContinueToBreakInSwitchRector: null | ||
|
||
# see https://www.php.net/manual/en/function.ldap-first-attribute.php | ||
Rector\Core\Rector\FuncCall\RemoveFuncCallArgRector: | ||
$argumentPositionByFunctionName: | ||
ldap_first_attribute: [2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
rules/php53/src/Rector/Assign/ClearReturnNewByReferenceRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Php53\Rector\Assign; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\Assign; | ||
use PhpParser\Node\Expr\AssignRef; | ||
use PhpParser\Node\Expr\New_; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Rector\Core\RectorDefinition\CodeSample; | ||
use Rector\Core\RectorDefinition\RectorDefinition; | ||
|
||
/** | ||
* @sponsor Thanks https://twitter.com/afilina for sponsoring this rule | ||
|
||
* @see https://3v4l.org/UJN6H | ||
* @see \Rector\Php53\Rector\Assign\ClearReturnNewByReferenceRector | ||
*/ | ||
final class ClearReturnNewByReferenceRector extends AbstractRector | ||
{ | ||
public function getDefinition(): RectorDefinition | ||
{ | ||
return new RectorDefinition('Remove reference from "$assign = &new Value;"', [ | ||
new CodeSample( | ||
<<<'CODE_SAMPLE' | ||
$assign = &new Value; | ||
CODE_SAMPLE | ||
, | ||
<<<'CODE_SAMPLE' | ||
$assign = new Value; | ||
CODE_SAMPLE | ||
), ]); | ||
} | ||
|
||
public function getNodeTypes(): array | ||
{ | ||
return [AssignRef::class]; | ||
} | ||
|
||
/** | ||
* @param AssignRef $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
if (! $node->expr instanceof New_) { | ||
return null; | ||
} | ||
|
||
return new Assign($node->var, $node->expr); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
rules/php53/src/Rector/Variable/ReplaceHttpServerVarsByServerRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Php53\Rector\Variable; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\Variable; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Rector\Core\RectorDefinition\CodeSample; | ||
use Rector\Core\RectorDefinition\RectorDefinition; | ||
|
||
/** | ||
* @sponsor Thanks https://twitter.com/afilina for sponsoring this rule | ||
* | ||
* @see \Rector\Php53\Tests\Rector\Variable\ReplaceHttpServerVarsByServerRector\ReplaceHttpServerVarsByServerRectorTest | ||
* @see https://blog.tigertech.net/posts/php-5-3-http-server-vars/ | ||
*/ | ||
final class ReplaceHttpServerVarsByServerRector extends AbstractRector | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private const VARIABLE_RENAME_MAP = [ | ||
'HTTP_SERVER_VARS' => '_SERVER', | ||
'HTTP_GET_VARS' => '_GET', | ||
'HTTP_POST_VARS' => '_POST', | ||
'HTTP_POST_FILES' => '_FILES', | ||
'HTTP_SESSION_VARS' => '_SESSION', | ||
'HTTP_ENV_VARS' => '_ENV', | ||
'HTTP_COOKIE_VARS' => '_COOKIE', | ||
]; | ||
|
||
public function getDefinition(): RectorDefinition | ||
{ | ||
return new RectorDefinition('Rename old $HTTP_* variable names to new replacements', [ | ||
new CodeSample('$serverVars = $HTTP_SERVER_VARS;', '$serverVars = $_SERVER;'), | ||
]); | ||
} | ||
|
||
public function getNodeTypes(): array | ||
{ | ||
return [Variable::class]; | ||
} | ||
|
||
/** | ||
* @param Variable $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
foreach (self::VARIABLE_RENAME_MAP as $oldName => $newName) { | ||
if (! $this->isName($node, $oldName)) { | ||
continue; | ||
} | ||
|
||
$node->name = $newName; | ||
return $node; | ||
} | ||
|
||
return null; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...sts/Rector/Assign/ClearReturnNewByReferenceRector/ClearReturnNewByReferenceRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Php53\Tests\Rector\Assign\ClearReturnNewByReferenceRector; | ||
|
||
use Iterator; | ||
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Rector\Php53\Rector\Assign\ClearReturnNewByReferenceRector; | ||
use SplFileInfo; | ||
|
||
final class ClearReturnNewByReferenceRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideDataForTest() | ||
*/ | ||
public function test(string $file): void | ||
{ | ||
$this->doTestFileWithoutAutoload($file); | ||
} | ||
|
||
/** | ||
* @return Iterator<SplFileInfo> | ||
*/ | ||
public function provideDataForTest(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
protected function getRectorClass(): string | ||
{ | ||
return ClearReturnNewByReferenceRector::class; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
rules/php53/tests/Rector/Assign/ClearReturnNewByReferenceRector/Fixture/fixture.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
$instance = &new Foo(); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
$instance = new Foo(); | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
...s/php53/tests/Rector/Variable/ReplaceHttpServerVarsByServerRector/Fixture/fixture.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Php53\Tests\Rector\Variable\ReplaceHttpServerVarsByServerRector\Fixture; | ||
|
||
class SomeClass | ||
{ | ||
public function run() | ||
{ | ||
$tmp = $HTTP_SERVER_VARS[$var]; | ||
parse_str($HTTP_SERVER_VARS["QUERY_STRING"]); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Php53\Tests\Rector\Variable\ReplaceHttpServerVarsByServerRector\Fixture; | ||
|
||
class SomeClass | ||
{ | ||
public function run() | ||
{ | ||
$tmp = $_SERVER[$var]; | ||
parse_str($_SERVER["QUERY_STRING"]); | ||
} | ||
} | ||
|
||
?> |
34 changes: 34 additions & 0 deletions
34
.../Variable/ReplaceHttpServerVarsByServerRector/ReplaceHttpServerVarsByServerRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Php53\Tests\Rector\Variable\ReplaceHttpServerVarsByServerRector; | ||
|
||
use Iterator; | ||
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Rector\Php53\Rector\Variable\ReplaceHttpServerVarsByServerRector; | ||
use SplFileInfo; | ||
|
||
final class ReplaceHttpServerVarsByServerRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideDataForTest() | ||
*/ | ||
public function test(string $file): void | ||
{ | ||
$this->doTestFile($file); | ||
} | ||
|
||
/** | ||
* @return Iterator<SplFileInfo> | ||
*/ | ||
public function provideDataForTest(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixtures'); | ||
} | ||
|
||
protected function getRectorClass(): string | ||
{ | ||
return ReplaceHttpServerVarsByServerRector::class; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @afilina,
we have this habit in Rector, that any person/company that sponsors more rules that are useful and shared with community,
will get this "sponsor badge" above each sponsored rule as a small "thank you" for doing so.
Is this line ok? We can link also website. e.g.
* @sponsor Thanks https://twitter.com/afilina for sponsoring this rule - visit her on https://www.youtube.com/c/AnnaFilina