mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 16:30:51 +00:00
[Core] Override pModifiers() method to set final and abstract modifiers early on BetterStandardPrinter (#2328)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
2c0f802aaf
commit
e33bcf19be
|
@ -8435,7 +8435,7 @@ Add final to constants that does not have children
|
|||
class SomeClass
|
||||
{
|
||||
- public const NAME = 'value';
|
||||
+ public final const NAME = 'value';
|
||||
+ final public const NAME = 'value';
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -707,3 +707,7 @@ parameters:
|
|||
-
|
||||
message: '#Instead of "DateTime" class/interface use "Nette\\Utils\\DateTime"#'
|
||||
path: src/Application/VersionResolver.php
|
||||
|
||||
-
|
||||
message: '#Class cognitive complexity is 55, keep it under 50#'
|
||||
path: src/PhpParser/Printer/BetterStandardPrinter.php #41
|
||||
|
|
|
@ -24,6 +24,6 @@ abstract class ParentClass
|
|||
|
||||
class ChildClass extends ParentClass
|
||||
{
|
||||
public final const TEST_CONSTANT = 'value2';
|
||||
final public const TEST_CONSTANT = 'value2';
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Rector\Tests\Php81\Rector\ClassConst\FinalizePublicClassConstantRector
|
|||
|
||||
class SomeClass
|
||||
{
|
||||
public final const NAME = 'value';
|
||||
final public const NAME = 'value';
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -47,7 +47,7 @@ CODE_SAMPLE
|
|||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public final const NAME = 'value';
|
||||
final public const NAME = 'value';
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
|
|
|
@ -447,6 +447,29 @@ final class BetterStandardPrinter extends Standard implements NodePrinterInterfa
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override parent pModifiers to set position of final and abstract modifier early, so instead of
|
||||
*
|
||||
* public final const MY_CONSTANT = "Hello world!";
|
||||
*
|
||||
* it should be
|
||||
*
|
||||
* final public const MY_CONSTANT = "Hello world!";
|
||||
*
|
||||
* @see https://github.com/rectorphp/rector/issues/6963
|
||||
* @see https://github.com/nikic/PHP-Parser/pull/826
|
||||
*/
|
||||
protected function pModifiers(int $modifiers): string
|
||||
{
|
||||
return (($modifiers & Class_::MODIFIER_FINAL) !== 0 ? 'final ' : '')
|
||||
. (($modifiers & Class_::MODIFIER_ABSTRACT) !== 0 ? 'abstract ' : '')
|
||||
. (($modifiers & Class_::MODIFIER_PUBLIC) !== 0 ? 'public ' : '')
|
||||
. (($modifiers & Class_::MODIFIER_PROTECTED) !== 0 ? 'protected ' : '')
|
||||
. (($modifiers & Class_::MODIFIER_PRIVATE) !== 0 ? 'private ' : '')
|
||||
. (($modifiers & Class_::MODIFIER_STATIC) !== 0 ? 'static ' : '')
|
||||
. (($modifiers & Class_::MODIFIER_READONLY) !== 0 ? 'readonly ' : '');
|
||||
}
|
||||
|
||||
private function resolveContentOnExpr(Expr $expr, string $content): string
|
||||
{
|
||||
$parentNode = $expr->getAttribute(AttributeKey::PARENT_NODE);
|
||||
|
|
Loading…
Reference in New Issue
Block a user