Laravel: Method not found false positive (on Eloquent Model)
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...
What sort class is it? an enum perhaps? otherwise can you perhaps provide a failing test? https://github.com/phpactor/phpactor/blob/2fa7ab2bdd411356fecf05dc228890681b4dc93c/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/MissingMethodProvider.php#L151
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
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?
@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
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)
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.
I am facing similar issue.
I am also facing this issue