Use phpdoc conditional returns for access functions

Created on 4 September 2025, about 2 months ago

Problem/Motivation

The documented return type of several access functions is bool|\Drupal\Core\Access\AccessResultInterface, but static analysis tools (phpstan, phpstorm, etc) don't know when it's bool and when it's AccessResultInterface.

This is easily rectified with conditional return types.

Note this doesn't matter for core until phpstan level 7, but plenty of contrib and custom projects are affected.

Steps to reproduce

Can verify this solves some issues by counting number of errors on HEAD vs this branch:

./vendor/bin/phpstan analyse -c core/phpstan.neon.dist --error-format=raw --level=7 | wc -l

Before: 48100
After: 48071

Proposed resolution

@return ($return_as_object is true ? \Drupal\Core\Access\AccessResultInterface : bool)

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component

base system

Created by

🇦🇺Australia mstrelan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024