Skip to content

chore(phpstan): load module language constants via explicit allowlist - #13

Merged
mambax7 merged 2 commits into
XoopsModules27x:masterfrom
mambax7:master
Aug 11, 2026
Merged

mambax7 merged 2 commits into
XoopsModules27x:masterfrom
mambax7:master

Conversation

@mambax7

@mambax7 mambax7 commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two template refinements proven downstream in xtracy and xwhoops.

1. Language-constant loading in phpstan-bootstrap.php. The bootstrap now loads the module's own language files (_MI_*/_MA_*/_AM_* defines), so analysis resolves every constant to a real string — and catches a mistyped constant name — instead of baselining each one as unknown. First proven in xtracy, where it shrank the PHPStan baseline from 32 to 20 entries.

2. S115 suppression comment in sonar-project.properties. language/** is source-excluded, so the S115 ignore scoped to language/**/*.php never currently fires; the comment now records that the ignore is deliberately kept dormant as defense-in-depth (lifting the exclusion later cannot flood the report with S115 naming findings), so the pairing no longer reads as a contradiction. Applied with identical wording in xtracy (XoopsModules27x/xtracy#2) and xwhoops (XoopsModules27x/xwhoops#5).

Approach

The language loading is an explicit allowlist, never a glob: only named language-definition files can execute during analysis, so a stray PHP file in language/english (or the anti-indexing index.php stub) never runs. Consuming modules edit the list to match their files. Unlike the xtracy original, entries are wrapped in is_file() — the template must stay copy-paste safe for modules missing an entry (and for this repo, which has no language/ directory), while a file missing from the list stays loud through unknown-constant reports.

Testing

Full local gate green in this repo (composer qa: php-cs-fixer 0 findings, PHPStan no errors, Rector clean, PHPUnit passing) — proving the guarded block is a no-op where no language files exist.

Summary by Sourcery

Document shared XOOPS stub usage and extend static-analysis bootstrap to load module language constants, while clarifying SonarQube configuration and adding guidance for handling libraries that grab global handlers.

New Features:

  • Load module language constants from explicit allowlisted language files during PHPStan analysis so language defines are resolved and mistyped constants are surfaced.
  • Document the XOOPS 2.7.3 error-screen ownership API in the shared stub and describe how modules should guard usage based on their supported XOOPS version.
  • Add docs on hosting libraries that take global handlers, focusing on avoiding unsafe undo-after patterns by using injection seams or explicit configuration.

Enhancements:

  • Expand README with guidance on extending the shared XOOPS stub, including impacts on PHPStan baselines and best practices for adding new symbols.

CI:

  • Clarify SonarQube S115 suppression comments to document why the ignore remains dormant yet preserved for future language-file scanning scenarios.

Documentation:

  • Add a hosting guide for libraries that manipulate global handlers, outlining safe integration patterns in XOOPS modules.
  • Update README to reference the new guidance doc and to explain best practices for extending the shared XOOPS stub.

Summary by CodeRabbit

  • New Features

    • Added PHPStan stubs for XOOPS 2.7.3+ error-screen ownership APIs.
    • PHPStan bootstrap now loads available module English language definitions safely.
  • Documentation

    • Added guidance for integrating libraries that install global handlers.
    • Documented how to extend the shared stub, including compatibility and maintenance considerations.
    • Updated the changelog and README with the latest capabilities and usage guidance.
  • Chores

    • Clarified static-analysis suppression coverage for language files.

Teach the bootstrap template to load the module's own language files
(_MI_*/_MA_*/_AM_* defines) so analysis resolves every constant to a
real string -- and catches a mistyped name -- instead of baselining
each one as unknown. First proven in xtracy, where it shrank the
baseline from 32 to 20 entries.

The loading is an explicit allowlist, never a glob: only named
language-definition files can execute during analysis, so a stray PHP
file in language/english (or the anti-indexing index.php stub) never
runs. Consuming modules edit the list to match their files; is_file()
keeps the template copy-paste safe when an entry is absent, while a
file missing from the list stays loud through unknown-constant
reports.
language/** is excluded from sonar.sources, so the S115 ignore scoped
to language/**/*.php never currently fires. That is deliberate: the
scoped ignore stays as defense-in-depth so that lifting the exclusion
(e.g. to SAST-scan language files) cannot flood the report with S115
naming findings. Record that intent where the ignore is declared so
the pairing no longer reads as a contradiction.
Copilot AI lite review requested due to automatic review settings August 11, 2026 00:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sourcery-ai

sourcery-ai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds explicit loading of module language constants for PHPStan via an allowlisted set of language files, extends documentation around the shared XOOPS stub and global handler-hosting, documents new error-screen ownership functions in the stub, and clarifies the dormant Sonar S115 suppression for language files.

Sequence diagram for PHPStan bootstrap language-constant loading

sequenceDiagram
    participant PhpStan
    participant PhpstanBootstrap as phpstan-bootstrap.php
    participant LangAdmin as language_english_admin.php
    participant LangMain as language_english_main.php
    participant LangModinfo as language_english_modinfo.php

    PhpStan->>PhpstanBootstrap: require phpstan-bootstrap.php
    PhpstanBootstrap->>PhpstanBootstrap: foreach ['admin.php','main.php','modinfo.php']
    loop for each xoopsLanguageFile
        PhpstanBootstrap->>PhpstanBootstrap: is_file(__DIR__.'/language/english/'+xoopsLanguageFile)
        alt [file exists]
            PhpstanBootstrap->>LangAdmin: require_once admin.php
            PhpstanBootstrap->>LangMain: require_once main.php
            PhpstanBootstrap->>LangModinfo: require_once modinfo.php
        else [file missing]
            PhpstanBootstrap-->>PhpstanBootstrap: skip file (constants stay unknown)
        end
    end
    PhpstanBootstrap-->>PhpStan: module language constants _MI_*, _MA_*, _AM_* defined for analysis
Loading

File-Level Changes

Change Details Files
Load module language constants during PHPStan bootstrap using an explicit allowlist of language files guarded by existence checks.
  • Introduce foreach over a fixed set of language filenames to require language/english files when present.
  • Guard each file load with is_file() to keep the template safe in modules that do not have every listed file.
  • Unset temporary loop variables after loading to keep bootstrap scope clean.
phpstan-bootstrap.php
Document the extended XOOPS stub and new guidance on hosting libraries that grab global handlers, including error-screen ownership APIs.
  • Update README static analysis section to mention error-screen ownership functions and add an Extending the stub section with constraints and best practices.
  • Add CHANGELOG entries describing the new error-screen ownership API declarations, the hosting-a-library docs, and the implications of extending the stub.
  • Add a new docs page explaining how to host libraries that take process-wide global handlers without breaking their register/unregister lifecycle.
README.md
CHANGELOG.md
docs/hosting-a-library-that-grabs-global-handlers.md
Clarify that the Sonar S115 suppression for language constants is intentionally dormant because language files are source-excluded, kept as defense-in-depth.
  • Expand the comment above sonar.issue.ignore.multicriteria.x1 to explain the source exclusion of language/**, the dormant status of the S115 ignore, and its purpose if the exclusion is lifted.
sonar-project.properties
Declare XOOPS 2.7.3 error-screen ownership functions in the shared stub so modules no longer hand-copy them, with guidance on min_xoops compatibility.
  • Add stub declarations for xoops_recordErrorScreenOwner(), xoops_getRecordedErrorScreenOwner(), and xoops_releaseErrorScreenOwner() with caveats about min_xoops and function_exists guards.
  • Document that modules should prefer the shared stub over local copies to avoid drift and baseline breakage.
  • Note that the stub represents the latest core27 API and does not guarantee runtime availability on older sites.
stubs/xoops.stub

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds XOOPS 2.7.3 error-screen ownership stubs, allowlisted PHPStan language loading, SonarPHP documentation, README guidance, changelog entries, and a guide for integrating libraries that install global handlers.

Changes

XOOPS analysis support

Layer / File(s) Summary
Error-screen ownership API
stubs/xoops.stub, README.md, CHANGELOG.md
Adds declarations for recording, querying, and releasing the XOOPS error-screen owner. Documents version compatibility and function_exists() guards.
Allowlisted language loading
phpstan-bootstrap.php, sonar-project.properties
Loads only selected existing language files during PHPStan bootstrap. Documents the scoped S115 suppression for excluded language files.

Global handler integration guidance

Layer / File(s) Summary
Global handler integration guide
docs/hosting-a-library-that-grabs-global-handlers.md, CHANGELOG.md
Documents injection seams, handler pairing, teardown hazards, Whoops behavior, fallback checks, testing, and related libraries.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary PHPStan bootstrap change: loading module language constants through an explicit allowlist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In phpstan-bootstrap.php the language path is hardcoded to language/english/; consider deriving the language subdirectory from a single constant/config value so modules using a different default locale (or supporting multiple locales in analysis) don’t need to edit the bootstrap logic itself.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `phpstan-bootstrap.php` the language path is hardcoded to `language/english/`; consider deriving the language subdirectory from a single constant/config value so modules using a different default locale (or supporting multiple locales in analysis) don’t need to edit the bootstrap logic itself.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@greptile-apps

greptile-apps Bot commented Aug 11, 2026

Copy link
Copy Markdown

Greptile Summary

The PR extends the static-analysis template to load explicitly allowlisted module language definitions and adds XOOPS 2.7.3 error-screen ownership declarations, with accompanying documentation refinements.

  • Loads existing admin, main, and module-info language files during PHPStan bootstrap without globbing.
  • Documents Sonar's deliberately dormant language-file naming suppression.
  • Adds error-screen ownership function declarations and guidance for extending shared stubs.
  • Adds integration guidance for libraries that manage process-global handlers.

Confidence Score: 4/5

The PR appears safe to merge, with a non-blocking template-default omission for modules that define block language constants.

The guarded explicit loading is safe for absent files, but including blocks.php in the default allowlist would avoid unnecessary consumer customization and unknown-constant analysis noise.

Files Needing Attention: phpstan-bootstrap.php

Important Files Changed

Filename Overview
phpstan-bootstrap.php Adds guarded language-file loading; the allowlist omits the conventional blocks.php file despite naming it in the customization guidance.
stubs/xoops.stub Adds documented XOOPS 2.7.3 error-screen ownership API declarations and clearly preserves the runtime version-guard requirement.
docs/hosting-a-library-that-grabs-global-handlers.md Adds focused guidance on refusing global side effects through library injection seams rather than unbalancing lifecycle cleanup.
README.md Documents shared-stub extension risks, version compatibility, and the new integration guide.
sonar-project.properties Clarifies why the language naming suppression remains configured while language sources are excluded.

Reviews (1): Last reviewed commit: "chore(sonar): document why the dormant S..." | Re-trigger Greptile

Comment thread phpstan-bootstrap.php
// blocks.php, ...). The is_file() guard keeps the template copy-paste safe when
// an entry does not exist; a file you forget to LIST is loud, as PHPStan then
// reports every one of its constants as unknown.
foreach (['admin.php', 'main.php', 'modinfo.php'] as $xoopsLanguageFile) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Default allowlist omits blocks.php

The guidance names blocks.php as a conventional language-definition file, but the default allowlist omits it. Modules with scanned block code must therefore customize the list or retain avoidable unknown-constant errors and baseline entries.

Suggested change
foreach (['admin.php', 'main.php', 'modinfo.php'] as $xoopsLanguageFile) {
foreach (['admin.php', 'blocks.php', 'main.php', 'modinfo.php'] as $xoopsLanguageFile) {

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@stubs/xoops.stub`:
- Around line 194-201: Update the parameter name in the ownership-related stub
declarations xoops_recordErrorScreenOwner and xoops_releaseErrorScreenOwner from
$dirname to $token, matching the XOOPS 2.7.3 runtime declarations while
preserving their types, defaults, and return types.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ecfe32d-0f0d-40bd-bbff-03b17b883561

📥 Commits

Reviewing files that changed from the base of the PR and between 9fa6b55 and 7af7d96.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • README.md
  • docs/hosting-a-library-that-grabs-global-handlers.md
  • phpstan-bootstrap.php
  • sonar-project.properties
  • stubs/xoops.stub

Comment thread stubs/xoops.stub
Comment on lines +194 to +201
/** Record this module as the error-screen owner. $force takes an occupied seat. */
function xoops_recordErrorScreenOwner(string $dirname, bool $force = false): bool {}

/** The recorded owner's dirname, or '' when the seat is free. */
function xoops_getRecordedErrorScreenOwner(): string {}

/** Release the seat, but only if $dirname currently holds it. */
function xoops_releaseErrorScreenOwner(string $dirname): bool {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

runtime_files="$(fd -t f '^debugconfig\.php$' . || true)"
if [[ -z "$runtime_files" ]]; then
  echo "No debugconfig.php found."
  exit 0
fi

while IFS= read -r file; do
  rg -n -A4 -B2 'function xoops_(record|release)ErrorScreenOwner' "$file"
done <<< "$runtime_files"

rg -nP '\bxoops_(record|release)ErrorScreenOwner\s*\([^)]*\b(dirname|token)\s*:' \
  --glob '*.php' . || true

Repository: XoopsModules27x/module-devops

Length of output: 193


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo '--- stub declarations and nearby documentation ---'
sed -n '175,205p' stubs/xoops.stub

echo '--- local ownership API references ---'
rg -n -C2 'xoops_(record|release)ErrorScreenOwner|dirname:|token:' . \
  --glob '*.php' --glob '*.stub' --glob '*.inc' --glob '*.md' || true

echo '--- XOOPS 2.7.3 runtime declaration ---'
url='https://raw.githubusercontent.com/XOOPS/XoopsCore27/master/htdocs/include/debugconfig.php'
curl -fsSL "$url" | rg -n -A5 -B3 \
  'function xoops_(record|release)ErrorScreenOwner' || true

Repository: XoopsModules27x/module-devops

Length of output: 3715


Match the runtime parameter names.

XOOPS 2.7.3 declares $token for both ownership functions. PHP 8 named arguments require the stub and runtime to use the same parameter names.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@stubs/xoops.stub` around lines 194 - 201, Update the parameter name in the
ownership-related stub declarations xoops_recordErrorScreenOwner and
xoops_releaseErrorScreenOwner from $dirname to $token, matching the XOOPS 2.7.3
runtime declarations while preserving their types, defaults, and return types.

@mambax7
mambax7 merged commit 198f195 into XoopsModules27x:master Aug 11, 2026
9 checks passed
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

Successfully merging this pull request may close these issues.

2 participants