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

«Undefined array key» when using autowiring with decorator #693

Open
Niklan opened this issue Dec 19, 2023 · 0 comments · May be fixed by #721
Open

«Undefined array key» when using autowiring with decorator #693

Niklan opened this issue Dec 19, 2023 · 0 comments · May be fixed by #721
Labels
bug Something isn't working

Comments

@Niklan
Copy link

Niklan commented Dec 19, 2023

Bug report

On ^1.2 version, decorating a service using autowiring feature without explicit class for decorator, leads to an error:

[19-Dec-2023 10:55:19 UTC] PHP Warning:  Undefined array key "Drupal\phpstan_example\BarInterface" in /var/www/html/vendor/mglaman/phpstan-drupal/src/Drupal/ServiceMap.php on line 65
Warning: Undefined array key "Drupal\phpstan_example\BarInterface" in /var/www/html/vendor/mglaman/phpstan-drupal/src/Drupal/ServiceMap.php on line 65
TypeError thrown in /var/www/html/vendor/mglaman/phpstan-drupal/src/Drupal/DrupalServiceDefinition.php on line 130 while loading bootstrap file /var/www/html/vendor/mglaman/phpstan-drupal/drupal-autoloader.php: mglaman\PHPStanDrupal\Drupal\DrupalServiceDefinition::addDecorator(): Argument #1 ($definition) must be of type mglaman\PHPStanDrupal\Drupal\DrupalServiceDefinition, null given, called in /var/www/html/vendor/mglaman/phpstan-drupal/src/Drupal/ServiceMap.php on line 65

There is no issue on ~1.1 version, only on 1.2.0+

Code snippet that reproduces the problem

example.services.yml:

  Drupal\phpstan_example\Foo:
  Drupal\phpstan_example\BarInterface: '@Drupal\phpstan_example\Bar'
  Drupal\phpstan_example\Bar:
    decorates: Drupal\phpstan_example\Foo

This definition is valid and works, but PHPStan fails on them. If I add explicit class for decorator, it would work:

  Drupal\phpstan_example\Foo:
  Drupal\phpstan_example\BarInterface: '@Drupal\phpstan_example\Bar'
  Drupal\phpstan_example\Bar:
+   class: Drupal\phpstan_example\Bar
    decorates: Drupal\phpstan_example\Foo

Looks like related to #578, but still an issue.

phpstan_example.zip — an example module with a problem.


Basically, I have an interface defined in services.yml file which is an alias for a specific class that implements that interface. But that class is another service which decorates contrib one. In example above: Foo is contrib services, defined in third-party code, BarInterface — an interface for my decorator used as an alias for its definition and Bar is an actual decorator.

@Niklan Niklan added the bug Something isn't working label Dec 19, 2023
@mglaman mglaman linked a pull request Jan 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant