Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Privatization] Do not remove comment on ChangeReadOnlyPropertyWithDefaultValueToConstantRector #3204

Merged
merged 6 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/packages_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:

- run: composer config minimum-stability dev

# issue with array shape on just released 1.15.1
- run: composer require phpstan/phpdoc-parser:1.15.0

# test with current commit in a pull-request
-
run: composer require rector/rector-src dev-main#${{github.event.pull_request.head.sha}} --no-update
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"nette/utils": "^3.2.8",
"nikic/php-parser": "^4.15.2",
"ondram/ci-detector": "^4.1",
"phpstan/phpdoc-parser": "^1.15.0",
"phpstan/phpdoc-parser": "1.15.0",
"phpstan/phpstan": "^1.9.3",
"phpstan/phpstan-phpunit": "^1.2.2",
"react/event-loop": "^1.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Rector\Tests\Privatization\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector\Fixture;

class DoNotRemoveComment
{
// some comment
private $magicMethods = [
'__toString',
'__wakeup',
];

public function run()
{
foreach ($this->magicMethods as $magicMethod) {
echo $magicMethod;
}
}
}

?>
-----
<?php

namespace Rector\Tests\Privatization\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector\Fixture;

class DoNotRemoveComment
{
// some comment
private const MAGIC_METHODS = [
'__toString',
'__wakeup',
];

public function run()
{
foreach (self::MAGIC_METHODS as $magicMethod) {
echo $magicMethod;
}
}
}

?>
10 changes: 3 additions & 7 deletions rules/Privatization/NodeFactory/ClassConstantFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\Property;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Privatization\Naming\ConstantNaming;

final class ClassConstantFactory
{
public function __construct(
private readonly ConstantNaming $constantNaming,
private readonly PhpDocInfoFactory $phpDocInfoFactory
private readonly ConstantNaming $constantNaming
) {
}

Expand All @@ -36,10 +34,8 @@ public function createFromProperty(Property $property): ClassConst

$const->setAttribute(AttributeKey::PARENT_NODE, $classConst);

$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
$phpDocInfo->markAsChanged();

$classConst->setAttribute(AttributeKey::PHP_DOC_INFO, $phpDocInfo);
$classConst->setAttribute(AttributeKey::PHP_DOC_INFO, $property->getAttribute(AttributeKey::PHP_DOC_INFO));
$classConst->setAttribute(AttributeKey::COMMENTS, $property->getAttribute(AttributeKey::COMMENTS));
$classConst->setAttribute(AttributeKey::PARENT_NODE, $property->getAttribute(AttributeKey::PARENT_NODE));

return $classConst;
Expand Down