No Code Attached Yet bug
avatar ramalama
ramalama
15 Jul 2026

What happened?

Steps to reproduce the issue

  1. Add a file inside one of the analysed paths containing a call to one of the MVC factory methods with only the $name argument:
  function repro(\Joomla\CMS\MVC\Factory\MVCFactoryInterface $factory): void
  {
      $factory->createModel('Articles');
  }
  1. Run the PHPStan check:

libraries/vendor/bin/phpstan analyse

Version

5.4

Expected result

The analysis completes. Since $prefix is an optional parameter (createModel($name, $prefix = '', array $config = [])), calling the method with a single argument is valid code and
must not break static analysis.

Actual result

The whole PHPStan run aborts:

Internal error: Call to a member function getAttribute() on null while analysing file .../repro.php

In CI this fails the phpstan job for any PR touching such a file, with an error message that points to the analysed file instead of the actual culprit, making it very hard for
contributors to understand what is wrong.

Cause

The custom dynamic return type extension build/phpstan/src/DynamicReturnType/MVCFactoryInterfaceInterface.php guards only against calls without any arguments, but then
unconditionally reads the second argument:

  if (\count($methodCall->getArgs()) === 0) {
      return null;
  }

  $name   = str_replace("'", '', $methodCall->getArgs()[0]->value->getAttribute('rawValue'));
  $prefix = str_replace("'", '', $methodCall->getArgs()[1]->value->getAttribute('rawValue'));

For a one-argument call, getArgs()[1] is null; reading ->value on it yields null (warning only), and the subsequent getAttribute() call is the fatal error reported by PHPStan.

###Suggested fix

Bail out whenever fewer than the two required arguments are present, since the extension cannot resolve a class name without the prefix anyway:

  if (\count($methodCall->getArgs()) < 2) {
      return null;
  }

System Information

  • Joomla: current 5.4-dev / also present in later branches (file unchanged)
  • phpstan/phpstan 2.1.x, PHP 8.3

Additional Comments

Aditionally a custom rule for phpstan could be considered to generate a warning if one param is used. As far as I see the usage of just one param is deprecated for all subclasses of MVCFactoryInterface but the LegacyFactory

Problem applies also to createView and createTable methods

avatar ramalama ramalama - open - 15 Jul 2026
avatar joomla-cms-bot joomla-cms-bot - change - 15 Jul 2026
Labels Added: No Code Attached Yet bug
avatar joomla-cms-bot joomla-cms-bot - labeled - 15 Jul 2026
avatar ramalama
ramalama - comment - 15 Jul 2026

@Hackwar would appreciate your opinion on this.

avatar ramalama ramalama - change - 15 Jul 2026
The description was changed
avatar ramalama ramalama - edited - 15 Jul 2026

Add a Comment

Login with GitHub to post a comment