Giter Site home page Giter Site logo

Comments (11)

Wirone avatar Wirone commented on June 10, 2024 2

Ahhh, this way 😅. I think there are 2 possible paths:

  • make a pretty dumb and risky fixer that will just change ->__invoke() to (), leaving responsibility for verifying it to the user
  • make a context-aware, non-risky fixer that would change ->__invoke() to () only if we know the class being invoked and that class has __invoke() defined. BUT this is pretty much unachievable, because Fixer has context limited to a single file and most probably ->__invoke() is called outside of a invokable class, not inside of it. So I believe there are pretty low chances we can make it both safe and useful. We also don't support inheritance.

In general, seems like a job more for a Rector than Fixer.

from php-cs-fixer.

julienfalque avatar julienfalque commented on June 10, 2024 2

@keradus Yes, the situations are not the same. We may prefer to avoid (string) $foo in case $foo type changes and silently introduces unexpected casts: it's not very type safe. However, $foo() is only compatible with callable type, so static analysis can have you covered: callable acts like an interface.

from php-cs-fixer.

mvorisek avatar mvorisek commented on June 10, 2024 1

The only case I see where this will fail is when __invoke() is not defined but __call() is. Although that seems unlikely, the fixer should be risky for that reason.

It does not matter, __call() has different intent and usage. We can safely (and in non-risky way) change $obj->__invoke(/* args */) to shorter $obj(/* args */).

It matters - https://3v4l.org/AYFu3, but I am neutral if it should be risky or not.

from php-cs-fixer.

julienfalque avatar julienfalque commented on June 10, 2024 1

Fixing from ($foo)() to $foo->__invoke() is much more risky than from $foo->__invoke() to ($foo)(): (almost) all objects with __invoke() method are callable, but a lot of callables are not objects with __invoke() method. I would only implement the latter.

from php-cs-fixer.

mvorisek avatar mvorisek commented on June 10, 2024

Is this feasible, are you sure __invoke cannot be any/unknown method?

from php-cs-fixer.

julienfalque avatar julienfalque commented on June 10, 2024

What do you mean? As long as the __invoke() method exists, the object is callable as a function. The only case I see where this will fail is when __invoke() is not defined but __call() is. Although that seems unlikely, the fixer should be risky for that reason.

from php-cs-fixer.

mvorisek avatar mvorisek commented on June 10, 2024

You are right - https://3v4l.org/fPaLC - 👍. I thought __invoke() to be present only on Closure.

from php-cs-fixer.

Wirone avatar Wirone commented on June 10, 2024

The only case I see where this will fail is when __invoke() is not defined but __call() is. Although that seems unlikely, the fixer should be risky for that reason.

It does not matter, __call() has different intent and usage. We can safely (and in non-risky way) change $obj->__invoke(/* args */) to shorter $obj(/* args */).

from php-cs-fixer.

julienfalque avatar julienfalque commented on June 10, 2024

IMO the fixer is pretty simple to implement, and since the risky situation is very unlikely, I think it's fine to have it in PHP CS Fixer.

from php-cs-fixer.

Wirone avatar Wirone commented on June 10, 2024

@julienfalque of course, I am not against this rule, I just think it will be risky anyway, since we just can't ensure proper context (including inheritance).

Side question: should the rule support 2-way standardisation? Or we consider using short invocation as a promoted standard?

from php-cs-fixer.

keradus avatar keradus commented on June 10, 2024

@julienfalque in context of Wirone#5 (comment) , do you want to keep this ticket open ?

from php-cs-fixer.

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.