0

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?

ToX 82
  • 1,064
  • 12
  • 35
  • 1
    When you point mouse over $user "$user = $this->findUserData($userId);" what is @var type ??? – Salines Feb 15 '20 at 21:07
  • It's `App\Model\Table\entity`. Fun fact, if I move the whole find into the `restoreBudget()` method (thus not calling an external method anymore), that warning disappears... – ToX 82 Feb 15 '20 at 21:21
  • 1
    Bingo! You are right, there is a `* @return entity User` in the comment... removing it removes the warning too – ToX 82 Feb 15 '20 at 21:25
  • Don't remove, change variable name , or add @var Cake\Datasource\EntityInterface $user in restoreBudget method – Salines Feb 15 '20 at 21:28
  • I have managed to fix it by replacing the return statement like this: `* @return \Cake\Datasource\EntityInterface User` – ToX 82 Feb 16 '20 at 07:49

0 Answers0