Skip to content

Commit

Permalink
[Privatization] Do not remove comment on ChangeReadOnlyPropertyWithDe…
Browse files Browse the repository at this point in the history
…faultValueToConstantRector (#3204)

* [Privatization] Do not remove comment on ChangeReadOnlyPropertyWithDefaultValueToConstantRector

* Fixed 🎉

* [ci-review] Rector Rectify

* pin to phpstan/phpdoc-parser 1.15.0

* require pin phpstan/phpdoc-parser:1.15.0 as 1.15.1 got issue on array shape

* require pin phpstan/phpdoc-parser:1.15.0 as 1.15.1 got issue on array shape

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Dec 16, 2022
1 parent 79a4c3a commit dec1ddd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
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

0 comments on commit dec1ddd

Please sign in to comment.