mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 06:18:07 +01:00
* [BetterStandardPrinter] Fixes #4691 Donot change convert string literal comment * handle spacing * [ci-review] Rector Rectify * fix conflict * [ci-review] Rector Rectify * try --debug * Trigger notification * phpstan * phpstan Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
parent
0b3f6446f3
commit
4087029cb9
@ -109,15 +109,12 @@ CODE_SAMPLE
|
||||
return $methodCall;
|
||||
}
|
||||
|
||||
private function refactorGetCallFuncCall(
|
||||
MethodCall $methodCall,
|
||||
FuncCall $funcCall,
|
||||
Expr $firstArgumentValue
|
||||
): ?MethodCall {
|
||||
private function refactorGetCallFuncCall(MethodCall $methodCall, FuncCall $funcCall, Expr $expr): ?MethodCall
|
||||
{
|
||||
if ($this->isName($funcCall, 'get_class')) {
|
||||
$getClassArgumentValue = $funcCall->args[0]->value;
|
||||
|
||||
if ($this->areNodesEqual($firstArgumentValue, $getClassArgumentValue)) {
|
||||
if ($this->areNodesEqual($expr, $getClassArgumentValue)) {
|
||||
unset($methodCall->args[1]);
|
||||
|
||||
return $methodCall;
|
||||
|
@ -147,20 +147,6 @@ final class VisibilityManipulator
|
||||
$this->replaceVisibilityFlag($node, 'private');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Property|ClassConst $node
|
||||
*/
|
||||
private function replaceVisibilityFlag(Node $node, string $visibility): void
|
||||
{
|
||||
$visibility = strtolower($visibility);
|
||||
|
||||
if ($visibility !== self::STATIC && $visibility !== self::ABSTRACT && $visibility !== self::FINAL) {
|
||||
$this->removeOriginalVisibilityFromFlags($node);
|
||||
}
|
||||
|
||||
$this->addVisibilityFlag($node, $visibility);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Class_|ClassMethod|Property|ClassConst $node
|
||||
*/
|
||||
@ -208,4 +194,18 @@ final class VisibilityManipulator
|
||||
get_class($node)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Property|ClassConst $node
|
||||
*/
|
||||
private function replaceVisibilityFlag(Node $node, string $visibility): void
|
||||
{
|
||||
$visibility = strtolower($visibility);
|
||||
|
||||
if ($visibility !== self::STATIC && $visibility !== self::ABSTRACT && $visibility !== self::FINAL) {
|
||||
$this->removeOriginalVisibilityFromFlags($node);
|
||||
}
|
||||
|
||||
$this->addVisibilityFlag($node, $visibility);
|
||||
}
|
||||
}
|
||||
|
@ -173,8 +173,8 @@ final class BetterStandardPrinter extends Standard
|
||||
$content = $this->contentPatcher->rollbackValidAnnotation(
|
||||
$contentOriginal,
|
||||
$content,
|
||||
ContentPatcher::VALID_ANNOTATION_RETURN_EXPLICIT_FORMAT_REGEX,
|
||||
ContentPatcher::INVALID_ANNOTATION_RETURN_EXPLICIT_FORMAT_REGEX
|
||||
ContentPatcher::VALID_ANNOTATION_VAR_RETURN_EXPLICIT_FORMAT_REGEX,
|
||||
ContentPatcher::INVALID_ANNOTATION_VAR_RETURN_EXPLICIT_FORMAT_REGEX
|
||||
);
|
||||
|
||||
// add new line in case of added stmts
|
||||
|
@ -81,16 +81,16 @@ final class ContentPatcher
|
||||
public const INVALID_ANNOTATION_ROUTE_LOCALIZATION_REGEX = '#^\s+\/\*\*\s+\s+\*\s+@.*(\s+\*\s{0,}[^"]*=\s{0,}[^"]*,?){1,}.*\)\s+\*\s+\*\/#msU';
|
||||
|
||||
/**
|
||||
* @see https://regex101.com/r/EA1xRY/2
|
||||
* @see https://regex101.com/r/EA1xRY/6
|
||||
* @var string
|
||||
*/
|
||||
public const VALID_ANNOTATION_RETURN_EXPLICIT_FORMAT_REGEX = '#^\s{0,}\* @return\s+(\(.*\)|(".*")(\|".*"){1,})$#msU';
|
||||
public const VALID_ANNOTATION_VAR_RETURN_EXPLICIT_FORMAT_REGEX = '#\*\s+@(var|return)\s+(\(.*\)|(".*")(\|".*")|("?.*"?){1,})$#msU';
|
||||
|
||||
/**
|
||||
* @see https://regex101.com/r/LprF44/3
|
||||
* @see https://regex101.com/r/LprF44/8
|
||||
* @var string
|
||||
*/
|
||||
public const INVALID_ANNOTATION_RETURN_EXPLICIT_FORMAT_REGEX = '#^\s{0,}\* @return([^\s].*|\s[^"\s]*)$#msU';
|
||||
public const INVALID_ANNOTATION_VAR_RETURN_EXPLICIT_FORMAT_REGEX = '#\*\s+@(var|return)([^\s].*|\s[^"\s]*|([^"]*[^"]))$#msU';
|
||||
|
||||
/**
|
||||
* @see https://regex101.com/r/4mBd0y/2
|
||||
@ -178,6 +178,7 @@ final class ContentPatcher
|
||||
* @see https://github.com/rectorphp/rector/issues/4476
|
||||
* @see https://github.com/rectorphp/rector/issues/4620
|
||||
* @see https://github.com/rectorphp/rector/issues/4652
|
||||
* @see https://github.com/rectorphp/rector/issues/4691
|
||||
*/
|
||||
public function rollbackValidAnnotation(
|
||||
string $originalContent,
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Issues\Issue4691\DoNotChangeExplicitQuotedStringComment;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DoNotChangeExplicitQuotedStringCommentTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
// bin/rector process ... --config config/some_config.php
|
||||
|
||||
protected function provideConfigFileInfo(): SmartFileInfo
|
||||
{
|
||||
return new SmartFileInfo(__DIR__ . '/config/some_config.php');
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Issues\Issue4691\DoNotChangeExplicitQuotedStringComment\Fixture;
|
||||
|
||||
final class DemoFile
|
||||
{
|
||||
/**
|
||||
* @var boolean|"frozen"|array
|
||||
*/
|
||||
public $use_session = \true;
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Set\ValueObject\SetList;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
|
||||
$parameters->set(Option::SETS, [SetList::DEAD_CODE]);
|
||||
};
|
@ -67,7 +67,7 @@ final class ConfigurableRectorRule implements Rule
|
||||
|
||||
private function hasRectorInClassName(Class_ $class): bool
|
||||
{
|
||||
if ($class->namespacedName === null) {
|
||||
if (! property_exists($class, 'namespacedName') || $class->namespacedName === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ final class ConfigurableRectorRule implements Rule
|
||||
|
||||
private function implementsConfigurableInterface(Class_ $class): bool
|
||||
{
|
||||
if ($class->namespacedName === null) {
|
||||
if (! property_exists($class, 'namespacedName') || $class->namespacedName === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user