Skip to content

Squiz.Commenting.FunctionComment truncates class name if it contains underscores #1197

Closed

Description

@mahmoudsaeed

Describe the bug

The Squiz.Commenting.FunctionComment sniff truncates class name if it contains underscores.

Code sample

/**
 * @return integer|WP_Error
 */
function test()
{
    return 0;
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="CS">
  <rule ref="Squiz.Commenting.FunctionComment"/>
</ruleset>

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above
  2. Run phpcbf test.php
  3. Check out the modified code. It corrected the integer type to int, but it truncated the class name WP_Error to just WP:
/**
 * @return int|WP
 */
function test()
{
    return 0;
}

Expected behavior

The code after modification should look like:

/**
 * @return int|WP_Error
 */
function test()
{
    return 0;
}

Versions (please complete the following information)

Operating System macOS 15.6
PHP version 8.4.7
PHP_CodeSniffer version 3.13.0
Standard Squiz
Install type Composer

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • I have read the Contribution Guidelines and this is not a support question.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the master branch of PHP_CodeSniffer.

Activity

  1. added this to the 3.13.3 milestone on Aug 21, 2025
  2. jrfnl commented on Aug 21, 2025

    @jrfnl
    Member

    @mahmoudsaeed Thanks for reporting this. I've been able to reproduce the issue.

    Looks like this bug was introduced in PHPCS 2.8.1 via PR squizlabs/PHP_CodeSniffer#1310. Cricky... very surprising that nobody has reported this before.... pff... let's get it fixed ;-)

  3. jrfnl commented on Aug 21, 2025

    @jrfnl
    Member

    Should be fixed by #1198. Testing appreciated.

  4. self-assigned this
    on Aug 21, 2025
  5. mahmoudsaeed commented on Aug 21, 2025

    @mahmoudsaeed
    Author

    Thanks for the quick fix! I tested it out and it works.

  6. jrfnl commented on Aug 21, 2025

    @jrfnl
    Member

    Thanks for testing @mahmoudsaeed !

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions