-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CodeQuality][CodingStyle] Handle crash on SimplifyIfReturnBoolRector…
…+NewlineAfterStatementRector+StringClassNameToClassConstantRector (#3175) * [CodeQuality][CodingStyle] Handle crash on SimplifyIfReturnBoolRector+NewlineAfterStatementRector+StringClassNameToClassConstantRector * Fixed 🎉 * Final touch: eol
- Loading branch information
1 parent
863fee3
commit 4ba03ab
Showing
4 changed files
with
92 additions
and
2 deletions.
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
32 changes: 32 additions & 0 deletions
32
tests/Issues/IndentationCrash/CodeQualityCodingStyleIndentationCrashTest.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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\IndentationCrash; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class CodeQualityCodingStyleIndentationCrashTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
/** | ||
* @return Iterator<array<string>> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureCodeQualityCodingStyle'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/code_quality_coding_style_configured_rule.php'; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ndentationCrash/FixtureCodeQualityCodingStyle/namespace_equal_prefix_class_string.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,42 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
class Foo {} | ||
|
||
class NamespaceEqualPrefixClassString | ||
{ | ||
public function hasMethod($classReflection, string $methodName): bool | ||
{ | ||
if ($classReflection->getName() !== 'App\Foo') { | ||
return false; | ||
} | ||
|
||
if (! str_starts_with($methodName, 'with')) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace App; | ||
|
||
class Foo {} | ||
|
||
class NamespaceEqualPrefixClassString | ||
{ | ||
public function hasMethod($classReflection, string $methodName): bool | ||
{ | ||
if ($classReflection->getName() !== \App\Foo::class) { | ||
return false; | ||
} | ||
return str_starts_with($methodName, 'with'); | ||
} | ||
} | ||
|
||
?> |
16 changes: 16 additions & 0 deletions
16
tests/Issues/IndentationCrash/config/code_quality_coding_style_configured_rule.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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector; | ||
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; | ||
use Rector\Config\RectorConfig; | ||
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rules([ | ||
SimplifyIfReturnBoolRector::class, | ||
NewlineAfterStatementRector::class, | ||
StringClassNameToClassConstantRector::class, | ||
]); | ||
}; |