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

Issue with ::class and Missing Return Statement in CI #335

Open
Morgy93 opened this issue Jan 16, 2025 · 2 comments
Open

Issue with ::class and Missing Return Statement in CI #335

Morgy93 opened this issue Jan 16, 2025 · 2 comments

Comments

@Morgy93
Copy link

Morgy93 commented Jan 16, 2025

Hello,

I’m encountering an issue where referencing a class with ::class causes the referenced class to throw the following error in CI (but not locally):

Method Two::getDependencies() should return array but return statement is missing.

As an example, this happens when working with data patches that have dependencies:

<?php

declare(strict_types=1);

use Magento\Framework\Setup\Patch\DataPatchInterface;

class One implements DataPatchInterface
{
    public static function getDependencies(): array
    {
        return [
            Two::class, // <--------------------------------------------------------------
        ];
    }
}
<?php

declare(strict_types=1);

use Magento\Framework\Setup\Patch\DataPatchInterface;

class Two implements DataPatchInterface
{
    public static function getDependencies(): array
    {
        return [];
    }
}

In this setup, the error is thrown in CI, even though everything runs fine locally.

Has anyone experienced this behavior? Could it be related to a specific configuration?
Any guidance on resolving this discrepancy would be greatly appreciated.

@shochdoerfer
Copy link
Member

Interesting. No one reported this so far, and I don't have a clue right now why I would fail.

Is this a Magento project or a Magento module? In the latter case, the only difference would be the way the generated files get created. Locally it's Magento logic, in CI it would be our module.

What happens if you replace the :class notation with a string with the fully qualified class name? Does the error appear in CI also?

And which PHPStan version are you using?

@Morgy93
Copy link
Author

Morgy93 commented Jan 16, 2025

I can currently reproduce this issue in two different custom modules: one using a data patch and another using a ViewModel.

For example, in the phtml file:
$viewModel = $viewModels->require(\Some\Example\Class::class);
This triggers the same "missing return type" error for the methods in Some\Example\Class.

Using the alternative:
$viewModel = $viewModels->require('Some\Example\Class');
doesn’t resolve the issue either; the error persists.
Additionally, phpcs complains with:
Use ::class notation instead. (Magento2.PHP.LiteralNamespaces.LiteralClassUsage) 😅

Versions:

  • phpstan/phpstan: 1.12.15
  • bitexpert/phpstan-magento: v0.32.0

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

2 participants