Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradeAttributeToAnnotationRector\Fixture;

final class OverrideAndSensitiveParameter extends Foo
{
#[\Override]
public function run(#[\SensitiveParameter] bool $param) {
if ($this->isTrue($param)) {
return 5;
}

return '10';
}

private function isTrue($value) {
return $value === true;
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradeAttributeToAnnotationRector\Fixture;

final class OverrideAndSensitiveParameter extends Foo
{
#[\Override]
public function run(
#[\SensitiveParameter]
bool $param) {
if ($this->isTrue($param)) {
return 5;
}

return '10';
}

private function isTrue($value) {
return $value === true;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\Class_\DowngradeAttributeToAnnotationRector\Fixture;

final class SkipAlreadyNewlinedOverrideAndSensitiveParameters extends Foo
{
#[\Override]
public function run(
#[\SensitiveParameter]
bool $param
) {
if ($this->isTrue($param)) {
return 5;
}

return '10';
}

private function isTrue($value) {
return $value === true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ final class DowngradeAttributeToAnnotationRector extends AbstractRector implemen
/**
* @var string[]
*/
private const SKIPPED_ATTRIBUTES = ['Attribute', 'ReturnTypeWillChange', 'AllowDynamicProperties'];
private const SKIPPED_ATTRIBUTES = [
'Attribute',
'ReturnTypeWillChange',
'AllowDynamicProperties',
'Override',
'SensitiveParameter',
];

/**
* @var DowngradeAttributeToAnnotation[]
Expand Down Expand Up @@ -114,7 +120,15 @@ public function refactor(Node $node): ?Node
(string) $oldTokens[$attrGroup->getEndTokenPos() + 1],
"\n"
)) {
// add new line
if ($node instanceof Param && (isset($oldTokens[$attrGroup->getStartTokenPos() - 1]) && ! str_contains(
(string) $oldTokens[$attrGroup->getStartTokenPos() - 1],
"\n"
))) {
// add new line before
$oldTokens[$attrGroup->getStartTokenPos() - 1]->text .= "\n";
}

// add new line after
$oldTokens[$attrGroup->getEndTokenPos() + 1]->text = "\n" . $oldTokens[$attrGroup->getEndTokenPos() + 1]->text;
$this->isDowngraded = true;
}
Expand Down