Expected type 'Cake\Datasource\EntityInterface'. Found 'App\Model\Table\entity'

489 Views Asked by At

I am not sure whether this is an issue with my code or intelephense, actually.

In my UsersTable I have a method that, given a user_id, fetches the user's data (through a call to another method) and makes a refound. Here is the code:

public function restoreBudget($userId)
{
    $user = $this->findUserData($userId);
    if ($user->subscription_plan->subscription_type == 'prepaid') {
        $user->credit = $user->credit + $user->price;
        $this->save($user);
    }
}

public function findUserData($id)
{
    $user = $this->find()
        ->contain(['SubscriptionPlans'])
        ->where([
            'Users.id' => $id
        ])
        ->first();

    return $user;
}

Now, everything seem to be working correctly, except that my IDE underlines the $user in $this->save($user), and intelephense is pointing to this error:

Expected type 'Cake\Datasource\EntityInterface'. Found 'App\Model\Table\entity'.

Why is that? Am I doing something wrong?

0

There are 0 best solutions below