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

Match arm comparison between *NEVER* and .... #25

Open
makroxyz opened this issue Jan 31, 2025 · 4 comments · May be fixed by laravel/framework#54452
Open

Match arm comparison between *NEVER* and .... #25

makroxyz opened this issue Jan 31, 2025 · 4 comments · May be fixed by laravel/framework#54452
Labels
bug Something isn't working

Comments

@makroxyz
Copy link

  • Larastan Version: 3.1.1
  • Laravel Version: 11.41

Description

Match arm comparison between NEVER and 'Domain\Registry\Models\Customer' is always false.
match.alwaysFalse
Match arm comparison between NEVER and 'Domain\Registry\Models\Lead' is always false.
match.alwaysFalse

I've tried almost everything... always same error. How can I solve?

Laravel code where the issue was found

function (Builder $q, string $morph) use ($value) {
    $column = match ($morph) {
        Customer::class,
        Lead::class => 'fullname',
        default => null
    };

    if ($column !== null) {
        $q->where($column, 'like', "%$value%");
    }
}
@makroxyz makroxyz added the bug Something isn't working label Jan 31, 2025
@calebdw
Copy link
Owner

calebdw commented Jan 31, 2025

The never type means that something is wrong and the type isn't known.

What is the output of?

function (Builder $q, string $morph) use ($value) {
    \PHPStan\dumpType($morph);
    $column = match ($morph) {
        //...

Also, are your morphs class strings or do you override the morph map?

@makroxyz
Copy link
Author

makroxyz commented Jan 31, 2025 via email

@makroxyz
Copy link
Author

makroxyz commented Feb 3, 2025

The never type means that something is wrong and the type isn't known.

What is the output of?

function (Builder $q, string $morph) use ($value) {
\PHPStan\dumpType($morph);
$column = match ($morph) {
//...
Also, are your morphs class strings or do you override the morph map?

This is full code

/** @return Builder<Opportunity> */
public function search(string $value): Builder
{
    return $this->builder->where(function (Builder $q) use ($value) {
        $q->whereHasMorph(
                'owner',
                [Customer::class, Lead::class],
                function (Builder $q, string $morph) use ($value) {
                    \PHPStan\dumpType($morph); // <--- *NEVER*
                    $column = match ($morph) {
                        Customer::class,
                        Lead::class => 'fullname',
                        default => null
                    };

                    if ($column !== null) {
                        $q->where($column, 'like', "%$value%");
                    }
                }
            );
    });
}

I can say that every whereHasMorph has this problem.

In this case Opportunity model has this relation:

 /** @return MorphTo<EloquentModel, $this> */
public function owner(): MorphTo
{
    return $this->morphTo();
}

@calebdw
Copy link
Owner

calebdw commented Feb 3, 2025

@makroxyz, this can be fixed in the framework

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants