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

Undefined method 'onEachSide'. intelephense(P1013) #2912

Closed
HugoSuarezJr opened this issue Jun 25, 2024 · 1 comment
Closed

Undefined method 'onEachSide'. intelephense(P1013) #2912

HugoSuarezJr opened this issue Jun 25, 2024 · 1 comment

Comments

@HugoSuarezJr
Copy link

HugoSuarezJr commented Jun 25, 2024

Describe the bug
Intelephense says undefined method 'onEachSide' for the Illuminate\Database\Eloquent\Collection::onEachSide method.

To Reproduce
$projects = Project::query()->paginate(10)->onEachSide(1);

Expected behavior
There should be no Intelephense error as this is a defined method and the code works just fine but it displays as if it were wrong in VScode.

Screenshots
Screenshot 2024-06-25 at 5 42 34 PM

Platform and version
VSCode and PHP Intelephense v1.10.4

@bmewburn
Copy link
Owner

bmewburn commented Jun 25, 2024

I think the problem is that paginate returns \Illuminate\Contracts\Pagination\LengthAwarePaginator which does not have this method declared. (You can hover on paginate to check this).
https://github.com/laravel/framework/blob/11.x/src/Illuminate/Contracts/Pagination/LengthAwarePaginator.php

You could assign the result on paginate to a variable and narrow the type like so:

/** @var \Illuminate\Pagination\AbstractPaginator $paginator */
$paginator = $query->paginate(10);

//or alternatively

if ($paginator instanceof \Illuminate\Pagination\AbstractPaginator) {
  $projects = $paginator->onEachSide(1);
}

Or you could fool the extension by adding the onEachSide method to the \Illuminate\Contracts\Pagination\LengthAwarePaginator interface in a (non-executable) stub file. For example

intelephense_helper.php

namespace Illuminate\Contracts\Pagination;

interface LengthAwarePaginator {
  function onEachSide($param) {};
}

carestad added a commit to carestad/framework that referenced this issue Feb 27, 2025
…ngthAwarePaginator`

Return types of all the subsequent calls are returning this, which in turn implements `\Illuminate\Contracts\Pagination\LengthAwarePaginator`

Related to bmewburn/vscode-intelephense#2912. Which I in turn had issues with locally where calling methods to the returned data from `->paginage()` did not auto complete.

Hope this is possible to backport to 11.x too if this is a change that is okay.
taylorotwell pushed a commit to laravel/framework that referenced this issue Feb 27, 2025
…ngthAwarePaginator` (#54826)

Return types of all the subsequent calls are returning this, which in turn implements `\Illuminate\Contracts\Pagination\LengthAwarePaginator`

Related to bmewburn/vscode-intelephense#2912. Which I in turn had issues with locally where calling methods to the returned data from `->paginage()` did not auto complete.

Hope this is possible to backport to 11.x too if this is a change that is okay.
taylorotwell pushed a commit to illuminate/database that referenced this issue Feb 27, 2025
…ngthAwarePaginator` (#54826)

Return types of all the subsequent calls are returning this, which in turn implements `\Illuminate\Contracts\Pagination\LengthAwarePaginator`

Related to bmewburn/vscode-intelephense#2912. Which I in turn had issues with locally where calling methods to the returned data from `->paginage()` did not auto complete.

Hope this is possible to backport to 11.x too if this is a change that is okay.
carestad added a commit to carestad/framework that referenced this issue Mar 5, 2025
…ngthAwarePaginator` (laravel#54826)

Return types of all the subsequent calls are returning this, which in turn implements `\Illuminate\Contracts\Pagination\LengthAwarePaginator`

Related to bmewburn/vscode-intelephense#2912. Which I in turn had issues with locally where calling methods to the returned data from `->paginage()` did not auto complete.

Hope this is possible to backport to 11.x too if this is a change that is okay.
taylorotwell pushed a commit to laravel/framework that referenced this issue Mar 5, 2025
…ngthAwarePaginator` (#54826) (#54917)

Return types of all the subsequent calls are returning this, which in turn implements `\Illuminate\Contracts\Pagination\LengthAwarePaginator`

Related to bmewburn/vscode-intelephense#2912. Which I in turn had issues with locally where calling methods to the returned data from `->paginage()` did not auto complete.

Hope this is possible to backport to 11.x too if this is a change that is okay.
taylorotwell pushed a commit to illuminate/database that referenced this issue Mar 5, 2025
…ngthAwarePaginator` (#54826) (#54917)

Return types of all the subsequent calls are returning this, which in turn implements `\Illuminate\Contracts\Pagination\LengthAwarePaginator`

Related to bmewburn/vscode-intelephense#2912. Which I in turn had issues with locally where calling methods to the returned data from `->paginage()` did not auto complete.

Hope this is possible to backport to 11.x too if this is a change that is okay.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants