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
Expand Up @@ -118,16 +118,19 @@ public function refactor(Node $node): ?Node
foreach ($node->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $key => $attribute) {
if ($this->shouldSkipAttribute($attribute)) {
if (isset($oldTokens[$attrGroup->getEndTokenPos() + 1]) && ! str_contains(
(string) $oldTokens[$attrGroup->getEndTokenPos() + 1],
"\n"
)) {
$endTokenPos = $attrGroup->getEndTokenPos();
$nextTokenPos = $endTokenPos + 1;
if (
$endTokenPos >= 0
&& isset($oldTokens[$nextTokenPos])
&& ! str_contains((string) $oldTokens[$nextTokenPos], "\n")
) {
// add new line
$oldTokens[$attrGroup->getEndTokenPos() + 1]->text = "\n" . $this->resolveIndentation(
$oldTokens[$nextTokenPos]->text = "\n" . $this->resolveIndentation(
$node,
$attrGroup,
$attribute
) . $oldTokens[$attrGroup->getEndTokenPos() + 1]->text;
) . $oldTokens[$nextTokenPos]->text;
$this->isDowngraded = true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types=1);

namespace Rector\Tests\Issues\IssueDowngradeMixedType\Fixture;

class SkipSameLineDeclareStrictType extends \stdClass implements \ArrayAccess, \Countable, \IteratorAggregate
{
public function offsetGet($key): mixed
{
}
}

?>
-----
<?php declare(strict_types=1);

namespace Rector\Tests\Issues\IssueDowngradeMixedType\Fixture;

use stdClass;
use ArrayAccess;
use Countable;
use IteratorAggregate;
use ReturnTypeWillChange;

class SkipSameLineDeclareStrictType extends stdClass implements ArrayAccess, Countable, IteratorAggregate
{
/**
* @return mixed
*/
#[ReturnTypeWillChange]
public function offsetGet($key)
{
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

use Rector\Config\RectorConfig;
use Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector;
use Rector\DowngradePhp80\Rector\Class_\DowngradeAttributeToAnnotationRector;
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector;
use Rector\DowngradePhp80\ValueObject\DowngradeAttributeToAnnotation;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->importNames();
$rectorConfig->rule(DowngradeTypedPropertyRector::class);
$rectorConfig->rule(DowngradeMixedTypeDeclarationRector::class);

$rectorConfig
->ruleWithConfiguration(DowngradeAttributeToAnnotationRector::class, [
new DowngradeAttributeToAnnotation('Symfony\Contracts\Service\Attribute\Required', 'required'),
]);
};
Loading