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

InterfaceReplacedWithAbstractClass should also replace typehints of the interface #33

Open
aragon999 opened this issue Feb 16, 2024 · 0 comments

Comments

@aragon999
Copy link
Member

aragon999 commented Feb 16, 2024

PHP Version

8.3

Shopware Version

6.4 -> 6.5

Plugin Version

main

Actual behaviour

+use Namespace\Of\TheFile\Shopware\Core\Checkout\Cart\AbstractCartPersister;

<snip>
 
-class CartPersister implements CartPersisterInterface
+class CartPersister extends AbstractCartPersister
 {
-    private CartPersisterInterface $cartPersister;
-
+    private readonly CartPersisterInterface $cartPersister;
     public function __construct(CartPersisterInterface $cartPersister)
     {
         $this->cartPersister = $cartPersister;
     }

Expected behaviour

+use Shopware\Core\Checkout\Cart\AbstractCartPersister;

<snip>
 
-class CartPersister implements CartPersisterInterface
+class CartPersister extends AbstractCartPersister
 {
-    private CartPersisterInterface $cartPersister;
-
-    public function __construct(CartPersisterInterface $cartPersister)
+    public function __construct(private readonly AbstractCartPersister $cartPersister)
     {
         $this->cartPersister = $cartPersister;
     }

So there are actually two issues, on the one hand only the class implements is replaced and not the interface on variables.

Furthermore the first rector iteration replaces the CartPersisterInterface by Shopware\Core\Checkout\Cart\AbstractCartPersister directly in the class declaration, i.e. in the current namespace, yielding the wrong namespace. The second issue could be fixed, if one appends a leading trailing slash to the InterfaceReplacedWithAbstractClass():

-            new InterfaceReplacedWithAbstractClass('Shopware\Core\Checkout\Cart\CartPersisterInterface', 'Shopware\Core\Checkout\Cart\AbstractCartPersister'),
-            new InterfaceReplacedWithAbstractClass('Shopware\Core\Content\Sitemap\Provider\UrlProviderInterface', 'Shopware\Core\Content\Sitemap\Provider\AbstractUrlProvider'),
-            new InterfaceReplacedWithAbstractClass('Shopware\Core\System\Snippet\Files\SnippetFileInterface', 'Shopware\Core\System\Snippet\Files\GenericSnippetFile'),
+            new InterfaceReplacedWithAbstractClass('Shopware\\Core\\Checkout\\Cart\\CartPersisterInterface', '\\Shopware\\Core\\Checkout\\Cart\\AbstractCartPersister'),
+            new InterfaceReplacedWithAbstractClass('Shopware\\Core\\Content\\Sitemap\\Provider\\UrlProviderInterface', '\\Shopware\\Core\\Content\\Sitemap\\Provider\\AbstractUrlProvider'),
+            new InterfaceReplacedWithAbstractClass('Shopware\\Core\\System\\Snippet\\Files\\SnippetFileInterface', '\\Shopware\\Core\\System\\Snippet\\Files\\GenericSnippetFile'),

(see: https://github.com/FriendsOfShopware/shopware-rector/blob/main/config/v6.5/renaming.php#L89-L91)

Steps to Reproduce?

Run the Shopware 6.5 migration on a plugin which implements the Shopware\Core\Checkout\Cart\CartPersisterInterface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant