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

[attributes] Make sure the target attribute class exists #6454

Merged
merged 1 commit into from
Nov 20, 2024
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
12 changes: 12 additions & 0 deletions rules/Php80/Rector/Class_/AnnotationToAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPStan\PhpDocParser\Ast\Node as DocNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\Reflection\ReflectionProvider;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
Expand Down Expand Up @@ -60,6 +61,7 @@ public function __construct(
private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly ReflectionProvider $reflectionProvider
) {
}

Expand Down Expand Up @@ -197,6 +199,11 @@ private function processGenericTags(PhpDocInfo $phpDocInfo): array
continue;
}

// make sure the attribute class really exists to avoid error on early upgrade
if (! $this->reflectionProvider->hasClass($annotationToAttribute->getAttributeClass())) {
continue;
}

$attributeGroups[] = $this->phpAttributeGroupFactory->createFromSimpleTag($annotationToAttribute);
return PhpDocNodeTraverser::NODE_REMOVE;
}
Expand Down Expand Up @@ -236,6 +243,11 @@ private function processDoctrineAnnotationClasses(PhpDocInfo $phpDocInfo, array
continue;
}

// make sure the attribute class really exists to avoid error on early upgrade
if (! $this->reflectionProvider->hasClass($annotationToAttribute->getAttributeClass())) {
continue;
}

$doctrineTagAndAnnotationToAttributes[] = new DoctrineTagAndAnnotationToAttribute(
$doctrineTagValueNode,
$annotationToAttribute,
Expand Down
7 changes: 7 additions & 0 deletions stubs/Doctrine/ORM/Mapping/DiscriminatorMap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Doctrine\ORM\Mapping;

class DiscriminatorMap
{
}
7 changes: 7 additions & 0 deletions stubs/Doctrine/ORM/Mapping/Embeddable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Doctrine\ORM\Mapping;

class Embeddable
{
}
8 changes: 8 additions & 0 deletions stubs/Doctrine/ORM/Mapping/ManyToOne.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Doctrine\ORM\Mapping;

class ManyToOne
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Sensio\Bundle\FrameworkExtraBundle\Configuration;

class IsGranted
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Sensio\Bundle\FrameworkExtraBundle\Configuration;

class ParamConverter
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Sensio\Bundle\FrameworkExtraBundle\Configuration;

class Security
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Bridge\Doctrine\Validator\Constraints;

class UniqueEntity
{
}
8 changes: 8 additions & 0 deletions stubs/Symfony/Component/Validator/Constraints/Choice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Symfony\Component\Validator\Constraints;

class Choice
{

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Issues\RenameAnnotationToAttributeAutoImport\Fixture;
namespace Rector\Tests\Issues\AnnotationToAttributeRenameAutoImport\Fixture;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -18,7 +18,7 @@ class WithExistingAttribute extends AbstractController
-----
<?php

namespace Rector\Tests\Issues\RenameAnnotationToAttributeAutoImport\Fixture;
namespace Rector\Tests\Issues\AnnotationToAttributeRenameAutoImport\Fixture;

use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down

This file was deleted.

48 changes: 0 additions & 48 deletions tests/Issues/FqcnAnnotationToAttribute/Fixture/fixture.php.inc

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.