Skip to content

Laravel: Method not found false positive (on Eloquent Model) #2420

Open

Description

@calebdw

Hello!

I'm in a Laravel Model and phpactor is reporting that a method in the same class does not exist---however, the method clearly exists and jump-to-definition works so I'm not sure what's going on...

image

Activity

  1. dantleech commented on Nov 6, 2023

    @dantleech
    Collaborator

    What sort class is it? an enum perhaps? otherwise can you perhaps provide a failing test?

  2. calebdw commented on Nov 6, 2023

    @calebdw
    Author

    After further inspection it looks to be a conflict with ide-helper helper file...apparently the helper file stub definition is replacing the real class definition instead of complimenting it

  3. reopened this on Nov 6, 2023
  4. dantleech commented on Nov 6, 2023

    @dantleech
    Collaborator

    i'm not sure what you mean by that, there is a Eagle\...\WorkOrder stub? or your class extends a class which has a stub, or there is a mixin annotation?

  5. calebdw commented on Nov 9, 2023

    @calebdw
    Author

    @dantleech

    One way the Laravel ide-helper works is by creating an _ide_helper_models.php file which contains stubs for all the models with auto-generated docblocks that look like the following:

    namespace Eagle\Maintenance\Models{
    /**
     * Eagle\Maintenance\Models\WorkOrder
     *
     * @property int $id
     * @property \Illuminate\Support\Carbon|null $created_at
     * @property \Illuminate\Support\Carbon|null $updated_at
     *  ...
     * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Data\Models\Audit> $audits
     * ...
     * @method static \Eagle\Maintenance\Builders\WorkOrderBuilder|WorkOrder canceled()
     * ...
     */
    	class WorkOrder extends \Eloquent {}
    }

    The problem is that the stub and the class have the same name/namespace and so phpactor seems to replace its definition with the stub. Instead what should happen is the stub should compliment the class without replacing it. I tested intelephense and it prompts which definition you would like to jump to whereas phpactor jumps straight to the stub

  6. changed the title [-]Method not found false positive[/-] [+]Laravel: Method not found false positive (on Eloquent Model)[/+] on Nov 9, 2023
  7. dantleech commented on Nov 9, 2023

    @dantleech
    Collaborator

    I see, I guess perhaps Phpactor should allow multiple files to define classes and use the combination of any definitions... although that would be potentially quite a large undertaking (while "jumping to either file" is probably not very hard, squeezing both definitions into the same Reflection class could be an issue and relates to this problem)

  8. dantleech commented on Nov 23, 2023

    @dantleech
    Collaborator

    hmm, also get this when including rector which has:

    <?php
    
    declare(strict_types=1);
    
    namespace PHPUnit\Framework;
    
    if (! class_exists('PHPUnit\Framework\TestCase')) {
        abstract class TestCase
        {
        }
    }
    

    which prevents the real PHPUnit TestCase from being found.

  9. hind-sagar-biswas commented on Apr 7, 2024

    @hind-sagar-biswas

    I am facing similar issue.

    1712483680_grim

  10. caliguIa commented on Apr 16, 2024

    @caliguIa

    I am also facing this issue

  11. khanakia commented on Sep 4, 2024

    @khanakia

    Is there any solution yet ?

  12. end3r-man commented on Oct 25, 2024

    @end3r-man

    I am facing similar issue.

    1712483680_grim

    any solution ??

  13. calebdw commented on Oct 25, 2024

    @calebdw
    Author

    Use:

    User::query()->where(...);
  14. end3r-man commented on Oct 25, 2024

    @end3r-man

    Use:

    User::query()->where(...);
    

    its working even having error, that Method where not found is show when

    -- 	  ["language_server_phpstan.enabled"] = true,
    -- 	  ["language_server_psalm.enabled"] = true,
    

    is enabled if is its false then their is no error also im unable to lsp for eloquent like where..., find...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions