Skip to content

fix(PEAR.FunctionCallSignature): avoid reindenting heredoc/nowdoc blocks#1417

Open
hakonharnes wants to merge 1 commit intoPHPCSStandards:4.xfrom
hakonharnes:fix/heredoc-nowdoc-function-call-signature-indentation
Open

fix(PEAR.FunctionCallSignature): avoid reindenting heredoc/nowdoc blocks#1417
hakonharnes wants to merge 1 commit intoPHPCSStandards:4.xfrom
hakonharnes:fix/heredoc-nowdoc-function-call-signature-indentation

Conversation

@hakonharnes
Copy link
Copy Markdown

Description

This PR fixes a bug in PEAR.Functions.FunctionCallSignature where phpcbf can produce syntactically invalid PHP when fixing multiline function calls containing flexible heredoc/nowdoc strings.

In affected cases, the sniff could adjust indentation across a heredoc/nowdoc scope and rewrite the closer indentation independently from the body indentation, resulting in mixed indentation and parse errors.

Changes made:

  • In PEAR.Functions.FunctionCallSignature:

    • Skip direct indent-fixing for T_END_HEREDOC / T_END_NOWDOC.
    • Skip changeCodeBlockIndent() when the related scope opener is T_START_HEREDOC / T_START_NOWDOC.
  • Regression coverage:

    • Added a focused heredoc multiline function-call case to:
      • src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc
      • src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc.fixed
    • Updated expected error lines in:
      • src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.php

Manual verification used during development:

<?php if (1) f(
	<<<E
	x
	E);
$ php -l repro.php
No syntax errors detected in repro.php

$ phpcbf --standard=PSR2 repro.php
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE                                                  FIXED  REMAINING
----------------------------------------------------------------------
/Users/hakon/phpcbf-codex-reprpo/repro.php            3      0
----------------------------------------------------------------------
A TOTAL OF 3 ERRORS WERE FIXED IN 1 FILE
----------------------------------------------------------------------

$ php -l repro.php
PHP Parse error:  Invalid indentation - tabs and spaces cannot be mixed in repro.php on line 4

Parse error: Invalid indentation - tabs and spaces cannot be mixed in repro.php on line 4
Errors parsing repro.php

Before this fix, the final lint can fail with mixed-indentation parse errors. After this fix, lint remains clean.

Suggested changelog entry

Fixed PEAR.Functions.FunctionCallSignature so phpcbf no longer corrupts indentation for flexible heredoc/nowdoc content in multiline function calls.

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.

@hakonharnes hakonharnes force-pushed the fix/heredoc-nowdoc-function-call-signature-indentation branch 2 times, most recently from c114f93 to 0a45e22 Compare April 22, 2026 15:12
@hakonharnes hakonharnes force-pushed the fix/heredoc-nowdoc-function-call-signature-indentation branch from 0a45e22 to 64b39b1 Compare April 22, 2026 15:23
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.

1 participant