mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-16 16:12:22 +00:00
add makeFinal() method
This commit is contained in:
parent
430b3e09ea
commit
6d0bf0b44b
|
@ -84,7 +84,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
$node->flags |= Class_::MODIFIER_FINAL;
|
||||
$this->makeFinal($node);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,14 @@ final class VisibilityManipulator
|
|||
$this->addVisibilityFlag($node, 'abstract');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Class_|ClassMethod $node
|
||||
*/
|
||||
public function makeFinal(Node $node): void
|
||||
{
|
||||
$this->addVisibilityFlag($node, 'final');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Property|ClassConst $node
|
||||
*/
|
||||
|
@ -39,7 +47,7 @@ final class VisibilityManipulator
|
|||
{
|
||||
$visibility = strtolower($visibility);
|
||||
|
||||
if ($visibility !== 'static' && $visibility !== 'abstract') {
|
||||
if ($visibility !== 'static' && $visibility !== 'abstract' && $visibility !== 'final') {
|
||||
$this->removeOriginalVisibilityFromFlags($node);
|
||||
}
|
||||
|
||||
|
@ -99,6 +107,10 @@ final class VisibilityManipulator
|
|||
if ($visibility === 'abstract') {
|
||||
$node->flags |= Class_::MODIFIER_ABSTRACT;
|
||||
}
|
||||
|
||||
if ($visibility === 'final') {
|
||||
$node->flags |= Class_::MODIFIER_FINAL;
|
||||
}
|
||||
}
|
||||
|
||||
private function ensureIsClassMethodOrProperty(Node $node, string $location): void
|
||||
|
|
|
@ -91,4 +91,9 @@ trait VisibilityTrait
|
|||
{
|
||||
$this->visibilityManipulator->makeStatic($node);
|
||||
}
|
||||
|
||||
public function makeFinal(Class_ $class): void
|
||||
{
|
||||
$this->visibilityManipulator->makeFinal($class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,7 @@ ksort($jsonContent['autoload']['psr-4']);
|
|||
ksort($jsonContent['autoload-dev']['psr-4']);
|
||||
|
||||
// 3. make core first
|
||||
$jsonContent['autoload']['psr-4'] = array_merge(
|
||||
['Rector\\' => 'src'],
|
||||
$jsonContent['autoload']['psr-4']
|
||||
);
|
||||
$jsonContent['autoload']['psr-4'] = array_merge(['Rector\\' => 'src'], $jsonContent['autoload']['psr-4']);
|
||||
$jsonContent['autoload-dev']['psr-4'] = array_merge(
|
||||
['Rector\\Tests\\' => 'tests'],
|
||||
$jsonContent['autoload-dev']['psr-4']
|
||||
|
@ -39,7 +36,8 @@ echo 'DONE';
|
|||
|
||||
|
||||
// used from: https://github.com/Symplify/Symplify/blob/64e1e07c87b1ec5551df07482d68c5085e76824a/packages/MonorepoBuilder/src/FileSystem/JsonFileManager.php#L70
|
||||
function inlineSections(string $jsonContent, array $inlineSections): string {
|
||||
function inlineSections(string $jsonContent, array $inlineSections): string
|
||||
{
|
||||
foreach ($inlineSections as $inlineSection) {
|
||||
$pattern = '#("' . preg_quote($inlineSection, '#') . '": )\[(.*?)\](,)#ms';
|
||||
$jsonContent = Strings::replace($jsonContent, $pattern, function (array $match): string {
|
||||
|
@ -54,7 +52,8 @@ function inlineSections(string $jsonContent, array $inlineSections): string {
|
|||
return $jsonContent;
|
||||
}
|
||||
|
||||
function inlineAuthorSection(string $jsonContent): string {
|
||||
function inlineAuthorSection(string $jsonContent): string
|
||||
{
|
||||
$authorsPattern = '#("authors":\s+\[)(?<authors>.*?)(\])#s';
|
||||
|
||||
$match = Strings::match($jsonContent, $authorsPattern);
|
||||
|
|
Loading…
Reference in New Issue
Block a user