Giter VIP home page Giter VIP logo

Comments (4)

sirbrillig avatar sirbrillig commented on May 27, 2024 2

Ohhh... thanks. I bet it's because in that case, $providerId is, lexically, inside of a function call's arguments, except that it's inside a closure and we don't account for that. I can fix it.

from phpcs-variable-analysis.

shvlv avatar shvlv commented on May 27, 2024 1

Thanks, @sirbrillig!

In this code, $providerId is never used, only declared, so I think this sniff should mark it as unused (but not undefined). Is there a reason why that would be wrong? I wanted to check before I closed this issue in case I'm mistaken.

Yes, there was a minimum reproducible example. So Unused warning would be pretty nice.

This should be fixed by #279

I've tested your code. It works nicely for $test = (function() { static $test;}); but snippet with add_action still triggers UndefinedVariable:

add_action('test', function () {
    static $providerId;
});

from phpcs-variable-analysis.

sirbrillig avatar sirbrillig commented on May 27, 2024

It looks like this is happening because the code that detects if a variable is inside a list of function call arguments is incorrectly finding the static variable.

if (Helpers::isTokenInsideFunctionCallArgument($phpcsFile, $stackPtr)) {

from phpcs-variable-analysis.

sirbrillig avatar sirbrillig commented on May 27, 2024

This should be fixed by #279

However, I wanted to ask, @shvlv: in your examples, would you expect those static variables to produce no warnings at all?

For example,

add_action('hook', static function (): void {
            static $providerId;
        });

In this code, $providerId is never used, only declared, so I think this sniff should mark it as unused (but not undefined). Is there a reason why that would be wrong? I wanted to check before I closed this issue in case I'm mistaken.

from phpcs-variable-analysis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.