-
-
Notifications
You must be signed in to change notification settings - Fork 394
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
Custom builder doc blocks are not parsed as builder generic #461
Comments
Hi, I cannot reproduce this. Added this /** @return \Illuminate\Support\Collection<User> */
public function testBug(): \Illuminate\Support\Collection
{
return User::query()
->groupBy('category_id')
->get(['category_id'])
->pluck('category_id');
} to the Can you give more info or make a PR with failing test? |
Ah sorry was testing it on my own model. Which has the following docblocks.
If I change those to the following larastan works but my auto complete in my IDE is gone :(
|
Your IDE does not support |
There is nothing we can do about that. Unless PHPStan also has some language server like Psalm. |
Nope PHPStorm does not support the following. /*
* @method static \App\Models\Builders\TransactionBuilder<Transaction> newModelQuery()
* @method static \App\Models\Builders\TransactionBuilder<Transaction> newQuery()
* @method static \App\Models\Builders\TransactionBuilder<Transaction> query()
*/
class Transaction extends Model
{
} Also the ide helper generates. /*
* @method static \App\Models\Builders\TransactionBuilder newModelQuery()
* @method static \App\Models\Builders\TransactionBuilder newQuery()
* @method static \App\Models\Builders\TransactionBuilder query()
*/
class Transaction extends Model
{
} To bad, without proper ide support I'm unable to continue using PHPStan :( |
Because it's not an Why do you need to put the docblocks anyway? Larastan should be able to undersand that. |
Also, you can use |
Because PHPStorm otherwise doesn't understand :(
That also doesn't work. No matter the order of methods. * @method static \App\Models\Builders\TransactionBuilder newModelQuery()
* @method static \App\Models\Builders\TransactionBuilder newQuery()
* @phpstan-method static \App\Models\Builders\TransactionBuilder<Transaction> query()
* @method static \App\Models\Builders\TransactionBuilder query() |
|
@BertvanHoekelen I'm not sure if it is possible to do something like that here. But we can discuss, sure. So what would be the rule to convert the docblocks? |
Well the ide-helper generates(and is correctly read by the ide): Or if there is no custom builder: |
But your original issue was with |
That one was generated by myself before installing the ide-helper to do it for me, my apologies. If I now create a new model called <?php
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* App\Foo
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Foo newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Foo newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Foo query()
* @mixin \Eloquent
*/
class Foo extends Model
{
//
} |
@mr-feek Do you also want to take this one? |
Sure, I can take a look |
That would be awesome @mr-feek.Thanks! If not I can give it a shot on Monday. |
Happy to help, but I can't reproduce. Feel free to push up a failing test case for me. I added the following to
then i made a test
And phpstan passed on max |
The issue is not about calling the method on it, but to get the model after calling And the extension we need is almost the same as the #479 We want to convert |
Hey @mr-feek, This test fails with:
<?php
declare(strict_types=1);
namespace Tests\Features\ReturnTypes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class CustomEloquentBuilderTest1
{
/**
* @return \Illuminate\Database\Eloquent\Collection<\Tests\Features\ReturnTypes\ModelWithCustomBuilderAndDocBlocks>
*/
public function testGetModelFromModelWithCustomBuilderQuery()
{
return ModelWithCustomBuilderAndDocBlocks::query()->get();
}
}
/**
* @method static \Tests\Features\ReturnTypes\CustomBuilder2|\Tests\Features\ReturnTypes\ModelWithCustomBuilderAndDocBlocks newModelQuery()
* @method static \Tests\Features\ReturnTypes\CustomBuilder2|\Tests\Features\ReturnTypes\ModelWithCustomBuilderAndDocBlocks newQuery()
* @method static \Tests\Features\ReturnTypes\CustomBuilder2|\Tests\Features\ReturnTypes\ModelWithCustomBuilderAndDocBlocks query()
*/
class ModelWithCustomBuilderAndDocBlocks extends Model
{
/**
* @param \Illuminate\Database\Query\Builder $query
*
* @return CustomBuilder2<\Tests\Features\ReturnTypes\ModelWithCustomBuilderAndDocBlocks>
*/
public function newEloquentBuilder($query): CustomBuilder2
{
return new CustomBuilder2($query);
}
}
/**
* @template TModelClass
* @extends Builder<TModelClass>
*/
class CustomBuilder2 extends Builder
{
} If the dockblocks of ModelWithCustomBuilderAndDocBlocks are changed to the following the test succeeds:
|
--level
used: maxThe behavior changed with PR #457
Description
Calling collection methods on a result collection gives errors like
Cannot call method pluck() on array<Illuminate\Database\Eloquent\Builder<mixed>>|Illuminate\Database\Eloquent\Collection.
This also happens to
count()
,contains()
,avg()
,first()
.Laravel code where the issue was found
The text was updated successfully, but these errors were encountered: