Skip to content

Generic/ScopeIndent: fix false positive after inline HTML before an open tag - #1488

Open
aymericcucherousset wants to merge 1 commit into
PHPCSStandards:4.xfrom
aymericcucherousset:issue-1434/fix-scopeindent-inline-html-open-tag
Open

Generic/ScopeIndent: fix false positive after inline HTML before an open tag#1488
aymericcucherousset wants to merge 1 commit into
PHPCSStandards:4.xfrom
aymericcucherousset:issue-1434/fix-scopeindent-inline-html-open-tag

Conversation

@aymericcucherousset

@aymericcucherousset aymericcucherousset commented Aug 23, 2026

Copy link
Copy Markdown

Description

Generic.WhiteSpace.ScopeIndent reported a false positive when a multi-line function call's opening line started with only whitespace before a <?=/<?php open tag (a common shape in template files), and an earlier, unrelated <?= ... ?> block appeared previously in the file.

The cause: PHP_CodeSniffer's tokenizer splits multi-line inline HTML into one T_INLINE_HTML token per physical line, so leading indentation before an open tag is its own T_INLINE_HTML token, not T_WHITESPACE, which only applies inside PHP code. ScopeIndentSniff's closing-parenthesis handling picked up that whitespace-only token as the "first token on the line", then called File::findStartOfStatement() to find the real statement start. Since T_INLINE_HTML isn't a stop token for that walk, it crossed into a previous, disjoint short-echo block and anchored the indentation check on unrelated code, producing an incorrect expected indent.

The fix skips a whitespace-only inline-HTML token so the sniff lands on the actual PHP open tag on that line, which findStartOfStatement() already treats as a statement start, avoiding the backward walk entirely for this case. The check is scoped to whitespace-only content specifically, so lines that start with meaningful inline HTML/markup before the open tag (a separate, already-existing and intentionally lenient behavior elsewhere in this file) are unaffected.

Suggested changelog entry

Fixed a Generic.WhiteSpace.ScopeIndent false positive for multi-line statements that follow whitespace-only inline HTML before a PHP open tag (e.g. in template files).

Related issues/external references

Fixes #1434

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.
  • I have opened a sister-PR in the documentation repository to update the Wiki.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generic.WhiteSpace.ScopeIndent false positive after arrow function method call in PHP template

1 participant