Phpinspectionsea: Feature/Improvement: tunable implicit magic method calls list or don't report __invoke

Created on 12 Oct 2017  路  2Comments  路  Source: kalessil/phpinspectionsea

This is about PHP | Php Inspections (EA Extended) | Code Style | Implicit magic method calls inspection.
TL;DR: I want to disable it for __invoke method calls.

Here is a (I sure not complete) list of ways to call __invoke of object:

$invokable = $this->searchHistoryWriter;
$invokable($this->filter);

\call_user_func([$this->searchHistoryWriter, '__invoke'], $this->filter);

$this->searchHistoryWriter->__invoke($this->filter);

Lets examine they one-by-one:

function-like call

Problems:

  • need to introduce variable, if invokable is in object property or you need to do weird thing like ($this->searchHistoryWriter)($this->filter)
  • you can't navigate to __invoke method of invokable directly 鈥斅爌hpstorm will point you to class property
  • you can't find usages of __invoke (tracked in https://youtrack.jetbrains.com/issue/WI-34223)

Pros:

  • PHP | Type compatibility | Parameter type inspection works (but doesn't work for ($invokable)($parameter) call. Looks like I have to open issue in jetbrains tracker)

call_user_func

Problems:

  • PHP | Type compatibility | Parameter type doesn't work
  • adds additional overhead (I'm not sure of impact of this)
  • is same as direct call to __invoke and probably should be marked by this inspection? 馃

Pros:

  • you can navigate to __invoke method directly
  • you can find __invoke usages

__invoke direct call

Problems:

  • is marked by this inspection 馃槃

Pros:

  • navigation works
  • find usages works
  • parameter type inspection works

So what I propose:聽igone __invoke direct calls by this inspection or add ability to disable it only for __invoke check in inspection settings.

Most helpful comment

If you use __invoke directly, why not have a real method name instead of using __invoke?

All 2 comments

If you use __invoke directly, why not have a real method name instead of using __invoke?

I rethinked this and found that I should require callables, so they are allowed to have no __invoke method.

Was this page helpful?
0 / 5 - 0 ratings