Resource icon

Static analysis for XenForo addons with PHPStan

1.3.2 (2026-12-01)​

  • On Windows generate wrote an alias stub with no aliases, from 0.11.1, so every legacy class name was undefined in every add-on analysed against that forum. The rule that skips a path naming no class accepted only / between segments, and PHP joins them with \ there. Reported as issue #3
  • On Windows a shortcut did not return the analysing add-on's own class extension: the file was matched against the add-on's directory with / only. Found by reading while fixing the above, and not run on Windows

1.3.1 (2026-12-01)​

  • generate --check no longer reports a set as out of date because it was generated through another path to the same forum, as one mounted in a container is when checked from its host. 1.3.0 compared the path recorded in each file's header; nothing reads it. generate leaves such a set as it is for the same reason, where it rewrote it before

1.3.0 (2026-12-01)​

  • generate --check notices a class extension added, removed or switched off since the set was generated, and a class renamed, and names each one. It applied only the test PHPStan applies, which is the XenForo version, so a set that was missing a new extension read as current. It now builds the set in memory as well and compares it with the files, writing nothing; the set needs nothing new in it, so one written by any release can be checked, and nothing has to be regenerated. A set that another release of this package wrote may differ for that reason alone, and is reported the same way

1.2.1 (2026-11-30)​

  • A BB code renderer's render() and renderAst() return a string
  • XF::getRootDirectory(), getSourceDirectory() and getAddOnDirectory() return a string, as do Util\File::canonicalizePath(), getCodeCachePath() and stripRootPathPrefix() An is_string() check written to narrow one of these now reports as already narrowed
  • Changelog: the 1.2.0 entry said an add-on's own ignore for a findByIds() report becomes unmatched; it stays silently redundant, and the entry now says so

1.2.0 (2026-11-30)​

  • $em->findByIds('XF:Thread', $ids) is typed as a collection of the entity named, and its identifier is no longer reported against the class-string annotation at level 5 or as an unresolved template type at level 6. It was missing from the shortcuts the package covers. An add-on's own ignore for either report is now redundant and is not reported as unmatched: it matches the same error the package's pattern does, so PHPStan counts it as used, and removing it is the only way to see that. Reported by an adopter
  • The conditions XenForo's own finders add, isValidUser(), inForum(), skipIgnored() and 59 more, return the finder they were called on, so a chain keeps its entity at level 7 and above
  • A core controller's *SaveProcess() returns a FormAction, through $this-> and parent::, so $form = parent::userSaveProcess($user) in a controller extension is typed. The three that are handed the form and return nothing are left alone
  • README: an entity's class given to a finder shortcut is XenForo 2.3's behaviour; an add-on with a 2.2 floor keeps the identifier form

1.1.0 (2026-11-30)​

  • An entity structure's $shortName is a string, its $contentType a string or null, and its $primaryKey one column or the list of a compound key
  • The finder's columnUtf8() and caseInsensitive() return a FinderExpression, and expression() is corrected to the same: XenForo documents it as returning the finder, so a method called on the result was accepted where the body returns an expression that has none

1.0.0 (2026-11-30)​

composer require --dev hampel/xenforo-phpstan:^1.0. Nothing in the package's behaviour
changed from 0.12.0, so a forum whose set was generated by 0.12.0 needs nothing more.

  • The first stable release. A ^1.0 constraint takes every later 1.x release with composer update, where a ^0.x constraint stopped at its own minor and each one had to be named
  • README: the members the stubs type, and the documented types they correct, are tables grouped by class in place of two long paragraphs
  • Tutorial: one sentence still said generate writes three files

0.12.0 (2026-11-30)​

composer require --dev hampel/xenforo-phpstan:^0.12, then vendor/bin/xenforo-phpstan generate
once per forum. Until it has run, PHPStan stops with `Scanned file
.../internal_data/phpstan/xf-options.php does not exist, and generate --check` says so first.

  • PHPStan runs against a XenForo 2.3.0 forum. The fragment named the forum's src/XF/Options.php to PHPStan, which 2.3.0 does not have, and a scan file that does not exist stops the run before anything is analysed. generate now writes a fourth file, xf-options.php: the forum's own class, byte for byte, or a file that declares nothing where the forum has none, and the fragment names that
  • The generated set keeps its format, so add-ons on an earlier release that share the forum go on reading it after one on 0.12 has regenerated

0.11.16 (2026-11-30)​

  • A FormAction's steps return the action, so a chain such as $form->basicEntitySave($entity, $input)->run() is typed: setup(), setupEntityInput(), validate(), validateEntity(), apply(), saveEntity(), complete(), basicEntitySave(), basicValidateServiceSave(), applyInTransaction() and logError() are $this, run() and isUsingTransaction() a bool
  • The controller's reroute(), rerouteController() and reroutePath() return a Reroute, and Router::prepareStringForUrl() a string. Reported by an adopter at level max

0.11.15 (2026-11-30)​


  • filter('name', [...]), an array of filters given for one name, is an array shape as filter([...]) has been since 0.7.0, on the controller and the request
  • Controller::filter()'s $type is corrected to take that array: XenForo documents a string, and the request the call is passed to hands an array to filterArray()
  • Typed where XenForo leaves them undeclared: XF::$DS, config() with no key on XF and XF\App (one key's value stays mixed), Entity::toArray(), AddOn::getInstalledAddOn(), escapeLike() on the adapter and the finder, the controller's $request and buildLinkHash(), Language::phrase() and dateTime(), and Request::getRequestMethod()
  • Request::getFile() is corrected from XenForo's upload-or-list: one upload asked for is the upload, null or false, and $multiple gives the list. Typing the controller's $request brought XenForo's docblock into force, which reported a single upload passed on as a list

0.11.14 (2026-11-30)​


  • $entity->getExistingValue('column') and getPreviousValue('column') are typed as getValue() has been since 0.11.12: each reads the same column, from the stored or the previous values, with the same fallback to the column's default and then null

0.11.13 (2026-11-30)​


  • extendClass() given a string is no longer reported against XenForo's class-string annotation, as the container shortcuts have not been since 0.1.0. An entity's array read typed as a string in 0.11.12 made \XF::extendClass($entry['cron_class']) a report where mixed had been accepted
  • The stub declares Stringable, which Controller::error() and noPermission() name as XenForo does. Under a phpVersion floor below 8.0 PHPStan does not know the interface and reported the stub itself; an add-on never saw that only because the stub sits under its excluded vendor/
  • Like
Reactions: Matt C.

0.11.12 (2026-11-30)​

  • An array read of an entity, $entity['column'], is typed as get() has been since 0.11.11: offsetGet() is the same call
  • $entity->getValue('column') is typed from the entity's @property line: the underscored one XenForo writes for the stored value of a column that has a getter, the plain one otherwise

0.11.11 (2026-11-29)​

  • $entity->get('column') is typed from the entity's @property line for that name, as a relation by name has been since 0.8.1, a column or relation a class extension adds included. It is what __get() calls, so it is the property read by another spelling; a name the entity does not declare, or one held in a variable, stays mixed

0.11.10 (2026-11-29)​

  • The finder's columnSqlName() and quote() return a string and Structure::$table is one, so a condition written as SQL by hand is no longer mixed at level 10
  • Util\Ip::parseIpRangeString() is corrected from the documented array|bool to false or the one array it builds, with its six keys typed, so a check for false leaves a shape whose printable, startRange and the rest can be read
  • README: the configuration template sets tmpDir: .phpstan.cache. Without it every add-on on a machine shares PHPStan's one default result cache, so each run after switching add-ons is cold and two runs at once write the same file. An adopter adds the line itself, with the .gitignore entry and the build.json removal the README shows; the tutorial's template carries the same line

0.11.9 (2026-11-29)​

  • A finder shortcut given an entity's class name, which XenForo 2.3 accepts, returns that entity's finder: its finder class where it has one, the generic Finder of that entity where it has none. It was a bare Finder yielding plain entities, and within the add-on that extends the entity it was typed as the entity extension, so every finder method on it was reported as undefined; that part was a defect of the own-extension rule since 0.2.2

0.11.8 (2026-11-29)​

  • An undeclared action* method of one of XenForo's own controller plugins returns a reply, as a controller's has since 0.8.0, so an extension of the warning or delete plugin returning parent::actionWarn() is no longer mixed. Only a method declared under XF\ControllerPlugin is typed: nothing enforces a reply from a plugin, and another add-on's may return anything
  • The templater's 34 form helpers that declare no return, formRow(), formTextBoxRow(), formSelectRow() and the rest, return a string, so an option renderer returning one is no longer reported at level 10
  • README: with no phpVersion set the floor comes from composer.json's php requirement, where it said the running PHP; a sed that makes an add-on's own options non-null in the generated options stub; an extension of an add-on that is not installed is excluded; an option renderer's inputName is not a string; a floor config inherits ignoreErrors as well, and which inherited ignores are then reported as unmatched; a view's parameters as a residual above level 8

0.11.7 (2026-11-27)​

  • Structure's $getters, $defaultWith, $options, $behaviors, $columnAliases and $withAliases are arrays, as $columns and $relations have been since 0.7.1, so an entity extension adding a getter to the structure it was handed is no longer an offset on mixed at level 10
  • Controller::formAction() returns a FormAction, and so do the account controller's accountDetailsSaveProcess() and preferencesSaveProcess(), which an extension calls through parent:: to add to the form
  • Request::getIp(), Templater::callMacro() and callAdsMacro() return a string, and a spam provider's $app is the application; XenForo declares none of them
  • corrected: Util\Ip::convertIpStringToBinary() and convertIpBinaryToString() return string|false, where XenForo documents bool|string and no path returns true
  • README: a docblock between an attribute and its method is not read, Mockery's higher-order expectations need the mocked class in the mock's type, and the chained generate is safe on a shared forum

Each was reported by an adopter at level max.

0.11.6 (2026-11-24)​

  • the API controller's apiResult(), apiSuccess() and apiBoolResult() return an ApiResult and apiError() an Error, and ApiResult::getApiResult() returns the result it was built from; XenForo declares none of them, so at level 9 every API action with a declared return type was reported as returning mixed. Reported by an adopter at level max

0.11.5 (2026-11-24)​

  • SimpleCache::getSet() returns a SimpleCacheSet, AddOn::getAddOnDirectory() and View::getTemplateName() a string, and App::getGlobalTemplateData() an array keyed by name; XenForo declares none of them. Templater::$defaultParams, which a templater extension reads directly, is an array keyed by name. Reported by an adopter at level max
  • corrected: XF::$version is a string and XF::$versionId an int. XenForo documents the pair with one block carrying both @var lines, which read as neither

0.11.4 (2026-11-23)​

  • getMasterPhrase() returns the phrase entity on the nineteen core entities that left it undeclared, from a cron entry and an option to a trophy and a reaction: each body returns the relation or a new phrase when it is empty, so never null. A prefix group and a widget had it from 0.10.8
  • getMasterTitlePhrase() and getMasterDescriptionPhrase() return the phrase entity on a widget definition, a widget position, an advertising position and an activity summary definition, for the same reason

0.11.3 (2026-11-23)​

  • TagRepository::normalizeTag() returns a string, and Str\Formatter::getProxiedUrlIfActive() and getProxiedUrlIfActiveExtended() a string or null; XenForo declares neither. Asked for by an adopter at level 10
  • UserRepository::getUsersByNames() returns a collection of users, and the names it did not find are strings; XenForo documents a bare ArrayCollection and a bare array
  • corrected: Mailer::getTransportFromOption() returns an AbstractTransport, as every branch of it does and as the mailer's constructor, setDefaultTransport() and send() require; XenForo documents the interface, which none of them accepts

0.11.2 (2026-11-22)​

  • a declared container key is typed through $app->get('key') and $subContainer->get('key') as well, which read the same entry as the array form and were left mixed in 0.11.0. Reported by an adopter
  • README: a declared container type that contains a comma is quoted, and a @phpstan-type alias is not known in one
  • README: with no phpVersion set PHPStan analyses for the PHP it runs on, and PHP 8.5 reports an int|null array key

0.11.1 (2026-11-22)​

  • generate wrote a legacy-aliases.stub.php PHP cannot parse when an add-on held PHP under a dot directory or any directory whose name is not an identifier, such as a git worktree checked out inside it: the alias took its namespace from the path. PHPStan drops a scan file it cannot parse without reporting it, so every legacy class name went undefined in every add-on analysed against that forum. Dot directories are now skipped, as is any path with a segment that is not an identifier, and dot directories under an add-on are left out of the scan as well, where a worktree declared every class of its add-on twice. Run generate again on a forum that was affected (#2)

0.11.0 (2026-11-22)​

  • an add-on's own container keys are typed where it declares them: xenforo.container maps a key of the application's container to a PHPDoc type, and xenforo.subContainers does the same per sub-container class. $app->container('key'), $app['key'], $container['key'], $this->container['key'] inside a sub-container and $subContainer['key'] are all answered; an undeclared key stays mixed. On one add-on at level 9 this cleared 37 of 120 reports and added none. Nothing changes for an add-on that declares no keys. Suggested by an adopter
  • below 1.0 a caret holds the minor: composer require --dev hampel/xenforo-phpstan:^0.11

0.10.9 (2026-11-22)​

  • XF\Http\Reader::get(), request(), getUntrusted() and requestUntrusted() corrected: $saveTo is string|resource|null, the path or stream the body is written to, and $error comes back as string|XF\Phrase|null. XenForo documents both as null, so an add-on downloading to a file was reported from level 5, and a check of the error after the call read as always false. Reported by an adopter

0.10.8 (2026-11-10)​

  • getMasterPhrase() on AbstractPrefixGroup and Widget typed as the XF\Entity\Phrase it returns, never null; XenForo declares neither, so above level 8 the phrase was mixed
  • getMasterPhrase() on StyleProperty and StylePropertyGroup corrected to the XF\Entity\Phrase entity it returns; XenForo's docblock resolves to the renderable XF\Phrase through an import, so the phrase's text and save() were reported as undefined from level 2
Thanks to @DragonByte Tech for the suggestion and bug report!

0.10.7 (2026-11-09)​

  • generate compared a set from an earlier minute as changed and rewrote it, because the date was stripped from the header before comparing but not from the exported 'generated' entry in classes.php; 0.10.6's "writes nothing when current" held only within the minute it was written. Reported by a reader the same day

0.10.6 (2026-11-09)​

  • generate writes nothing when the set already there differs from what it would write only by its date, and says so, so it can run in front of every analysis without invalidating PHPStan's result cache, which records the hash of every stub file
  • README: run generate before every analysis rather than remembering to; it costs a fraction of a second
  • Like
Reactions: DragonByte Tech
Back
Top Bottom