-
-
Notifications
You must be signed in to change notification settings - Fork 699
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
[SOLID] Rector\SOLID\Rector\Class_\FinalizeClassesWithoutChildrenRector: should not change Doctrine Entities #1639
Comments
Sorry, mistake from my side... It's handled correctly already. |
I'm encountering this issue again : docker run --rm -v $(pwd):/app rector_phar process --ansi --autoload-file /app/vendor/autoload.php --config /app/rector.yaml /app/src /app/tests --dry-run
Rector 0.6.x-dev@9a330e2
Config file: app/rector.yaml
1062/1062 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
1 file with changes
===================
1) app/src/SomeNamespace/ExpenseTag.php
---------- begin diff ----------
--- Original
+++ New
@@ -12,7 +12,7 @@
* @ORM\Table(name="expense_tag")
* @ORM\Entity()
*/
-class ExpenseTag
+final class ExpenseTag
{
/**
* @var Expense
----------- end diff -----------
Applied rules:
* Rector\SOLID\Rector\Class_\FinalizeClassesWithoutChildrenRector Here's the file : <?php
declare(strict_types=1);
namespace App\SomeNamespace;
use Doctrine\ORM\Mapping as ORM;
use SomeVendor\Snowflake\Snowflake;
/**
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="expense_tag")
* @ORM\Entity()
*/
class ExpenseTag
{
/**
* @var Expense
*
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Expense", inversedBy="expenseTags")
*/
private $expense;
/**
* @var Snowflake
*
* @ORM\Id
* @ORM\Column(name="tag_id", type="snowflake")
*/
private $tagId;
public function __construct(Expense $expense, Snowflake $tagId)
{
$this->expense = $expense;
$this->tagId = $tagId;
}
public function tagId(): Snowflake
{
return $this->tagId;
}
} I've tried adding this file "as is" in Could it be because it's running within Docker or with the phar ? (and Doctrine's annotation is not properly recognized ?) |
It probably is. It would be great if you'd add this test case to https://github.com/rectorphp/rector-prefixed If you run it with |
I fixed it by running Rector from the root of the project ( |
Could you update README for Docker to prevent that? |
Not sure it applies to the I'm not using the standard Rector container because I need to freeze Rector to a specific commit - so I'm using the PhpStan container in which I require rector instead, like this :
The |
Ok 👍 |
False hope... the issue is not resolved. Now that I managed to run Rector without issues with our custom phpstan.neon (by renaming it), I can get rid of Docker and run rector.phar directly (which is much more robust / fast - at least on my machine). But the issue is back. I managed to simplify it that much : $ php rector.phar process --rule "Rector\SOLID\Rector\Class_\FinalizeClassesWithoutChildrenRector" --dry-run src/Domain/Expenses/ExpenseTag.php
Rector 0.6.x-dev@f4bfaeb
Config file: rector.yaml
3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
1 file with changes
===================
1) src/Domain/Expenses/ExpenseTag.php
---------- begin diff ----------
--- Original
+++ New
@@ -12,7 +12,7 @@
* @ORM\Table(name="expense_tag")
* @ORM\Entity()
*/
-class ExpenseTag
+final class ExpenseTag
{
/**
* @var Expense
----------- end diff -----------
Applied rules:
* Rector\SOLID\Rector\Class_\FinalizeClassesWithoutChildrenRector I've tried to set the same thing in the playground repo, but it passed there :
Any ideas ? :( |
I'd debug This method should return true:
This is the method:
|
@TomasVotruba I took some time to investigate. Minimal code is : # src/Whatever/Task.php
<?php
namespace Rector\Whatever;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class Task
{
} Then I added
|
I have a theory... It might related to removed stubs, where are annotations located. Without those, Rector doesn't know about these classes and cannot parse it as an annotation. |
I don't think it could, as I reopened this issue 11 days ago and you merged the removal of the Or do you mean the removal of specific stub classes, like the annotations ones ? |
Now we know that the same issue happens with ECS's PHAR version and |
Any update on this? Just fixed partially-reated embeddables here: #2921 If still on, we'll need failing Github Action from you to confirm. Without that, we'll have to close it as wontfix |
Demo link is needed: https://getrector.org/demo |
I've tried running the current master version, and still get these : 10) src/Domain/Expenses/ExpenseTag.php
---------- begin diff ----------
--- Original
+++ New
@@ -12,7 +12,7 @@
* @ORM\Table()
* @ORM\Entity
*/
-class ExpenseTag
+final class ExpenseTag
{
/**
* @var Expense
----------- end diff -----------
Applied rules:
* Rector\SOLID\Rector\Class_\FinalizeClassesWithoutChildrenRector And the demo does the same! 👍 |
When you remove the HasLifecycle annotatoin (fixed in |
@TomasVotruba I upgraded to v0.7.6 and this issue still persists using rector.phar. I won't reopen, as I can't produce a demo nor a failing test, however I thought you should know. I've ignored this Rector in my code base, as ECS is already catching them too. |
rectorphp/rector-src@2eb244c Add failing test fixture for AddArrayReturnDocTypeRector rectorphp/rector-src@9102b49 add dump_with_depth helper function rectorphp/rector-src@679be38 add strict return type based return doc rectorphp/rector-src@8fc1759 check for iterable type before adding return type rectorphp/rector-src@d8e1531 remove non-array test fixtures rectorphp/rector-src@ff5f80c keep nullable array type rectorphp/rector-src@b45ff7a remove unused test rectorphp/rector-src@49f1596 Merge pull request #1639 from rectorphp/tv-make-array-return-doc-work-only-with-arrays
When using the level
solid
, it will turn every non-final class to final, including Doctrine entities.But as stated in Doctrine's documentation :
So it would be nice if there was a way for Rector to detect
@ORM\Entity
annotation and not process these classes.The text was updated successfully, but these errors were encountered: