Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squiz.PHP.LowercasePHPFunctions incorrectly reports on attribute names #3778

Closed
bytestream opened this issue Mar 20, 2023 · 2 comments · Fixed by #3779
Closed

Squiz.PHP.LowercasePHPFunctions incorrectly reports on attribute names #3778

bytestream opened this issue Mar 20, 2023 · 2 comments · Fixed by #3779

Comments

@bytestream
Copy link

Describe the bug
If an attribute name is also a PHP function name the LowercasePHPFunctionsSniff incorrectly throws an error.

Code sample

<?php declare(strict_types=1);

#[Attribute]
class Putenv
{
    public function __construct(public string $name, public string $value)
    {}
}

class FooBar
{
    #[Putenv('FOO', 'foo')]
    public function foo(): void
    {}
}

Custom ruleset

<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="foo">
    <rule ref="Squiz.PHP.LowercasePHPFunctions"></rule>
</ruleset>

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See error message displayed

FILE: /supportpal/test.php
--------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------------------------------------
 12 | ERROR | [x] Calls to PHP native functions must be lowercase; expected "putenv" but found "Putenv"
    |       |     (Squiz.PHP.LowercasePHPFunctions.CallUppercase)
--------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 67ms; Memory: 4MB

Expected behavior
No error

Versions (please complete the following information):

  • OS: Linux
  • PHP: 8.1
  • PHPCS: 3.7.2
  • Standard: Squiz

Additional context
Add any other context about the problem here.

@jrfnl
Copy link
Contributor

jrfnl commented Mar 20, 2023

@bytestream Thanks for reporting this. I've confirmed the issue and pulled PR #3779 to fix this. Testing appreciated.

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation May 4, 2023
@gsherwood gsherwood added this to the 3.8.0 milestone May 4, 2023
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release May 4, 2023
@jrfnl
Copy link
Contributor

jrfnl commented Dec 8, 2023

FYI: the fix for this issue is included in today's PHP_CodeSniffer 3.8.0 release.

As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
3 participants