Comments (11)
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.
@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.
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.
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.
Is this feasible, are you sure __invoke
cannot be any/unknown method?
from php-cs-fixer.
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.
You are right - https://3v4l.org/fPaLC - 👍. I thought __invoke()
to be present only on Closure
.
from php-cs-fixer.
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.
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.
@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.
@julienfalque in context of Wirone#5 (comment) , do you want to keep this ticket open ?
from php-cs-fixer.
Related Issues (20)
- ClassAttributesSeparationFixer - ['property' => 'none'] Add unwanted blank line when comment present
- Allow custom assertion methods in php_unit_test_case_static_method_calls
- Init command HOT 1
- Enum ordering support
- Bug in PHP-CS-Fixer with Laravel Pint 1.13.7 and php_unit_method_casing HOT 3
- `FullyQualifiedStrictTypesFixer` adds imports before PHP opening tag HOT 2
- Install now: 404 HOT 2
- `PhpUnitAttributesFixer` - ability to keep annotations HOT 2
- Please improve the documentation HOT 2
- PhpUnitDedicateAssertFixer is replacing functions with deprecated/removed method names of PHPUnit v9.1+
- Enforing variable to be CamelCase Or snake_cae but not both at the same time HOT 1
- constant_case rule alters constant names
- Add support for `*` syntax in `OrderedAttributesFixer`
- New rule: Interface implemenations split across lines HOT 2
- cs-fixer multicore bug with --path-mode and a specified file HOT 4
- Parallel runner not fixing any files HOT 26
- Displaying sum memory usage from all workers when parallel runner is used HOT 1
- Install documentation misses recommended "tools/php-cs-fixer" dir method HOT 5
- `ParallelConfigFactory` using named parameters behaves unexpectedly when omiting first argument
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-cs-fixer.