-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CodingStyle] Handle Change Exception variable usage after try catch …
…on CatchExceptionNameMatchingTypeRector (#360) * [CodingStyle] Handle Change Exception variable usage after try catch * [ci-review] Rector Rectify * stop change next after re-assign * fix * fixture usage in parent of try catch * Fixed 🎉 * cs fix * phpstan * final touch: fixture ensure always change next, stop after re-assign * [ci-review] Rector Rectify * stop on parent is FunctionLike * [ci-review] Rector Rectify * [ci-review] Rector Rectify * allow re-assign same variable * final touch Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
171417d
commit ecfaf21
Showing
6 changed files
with
231 additions
and
1 deletion.
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
37 changes: 37 additions & 0 deletions
37
...ctor/Catch_/CatchExceptionNameMatchingTypeRector/Fixture/change_variable_next_try.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,37 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture; | ||
|
||
class ChangeVariableNextTry | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
} catch (SomeException $typoException) { | ||
} | ||
|
||
$this->verify($typoException); | ||
$this->verify2($typoException); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture; | ||
|
||
class ChangeVariableNextTry | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
} catch (SomeException $someException) { | ||
} | ||
|
||
$this->verify($someException); | ||
$this->verify2($someException); | ||
} | ||
} | ||
|
||
?> |
45 changes: 45 additions & 0 deletions
45
...tor/Catch_/CatchExceptionNameMatchingTypeRector/Fixture/change_variable_next_try2.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,45 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture; | ||
|
||
class ChangeVariableNextTry2 | ||
{ | ||
public function run() | ||
{ | ||
if (rand(0, 1)) { | ||
try { | ||
} catch (SomeException $typoException) { | ||
} | ||
} | ||
|
||
if (isset($typoException)) { | ||
$this->verify($typoException); | ||
$this->verify2($typoException); | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture; | ||
|
||
class ChangeVariableNextTry2 | ||
{ | ||
public function run() | ||
{ | ||
if (rand(0, 1)) { | ||
try { | ||
} catch (SomeException $someException) { | ||
} | ||
} | ||
|
||
if (isset($someException)) { | ||
$this->verify($someException); | ||
$this->verify2($someException); | ||
} | ||
} | ||
} | ||
|
||
?> |
35 changes: 35 additions & 0 deletions
35
...tchExceptionNameMatchingTypeRector/Fixture/change_variable_next_try_reassign_same.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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture; | ||
|
||
class ChangeVariableNextTryReassignSameVariable | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
} catch (SomeException $typoException) { | ||
} | ||
|
||
$typoException = $typoException; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture; | ||
|
||
class ChangeVariableNextTryReassignSameVariable | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
} catch (SomeException $someException) { | ||
} | ||
|
||
$someException = $someException; | ||
} | ||
} | ||
|
||
?> |
41 changes: 41 additions & 0 deletions
41
...nNameMatchingTypeRector/Fixture/donot_change_variable_next_try_reassign_different.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,41 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture; | ||
|
||
class DonotChangeVariableNextTryReassignDifferent | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
} catch (SomeException $typoException) { | ||
} | ||
|
||
$this->verify($typoException); | ||
|
||
$typoException = 'test'; | ||
$this->verify($typoException); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture; | ||
|
||
class DonotChangeVariableNextTryReassignDifferent | ||
{ | ||
public function run() | ||
{ | ||
try { | ||
} catch (SomeException $someException) { | ||
} | ||
|
||
$this->verify($someException); | ||
|
||
$typoException = 'test'; | ||
$this->verify($typoException); | ||
} | ||
} | ||
|
||
?> |
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