I am trying to get type hinting to work with a custom User class in the Symfony 5.4 Security bundle and PHP 7.4. So I have this User class:
// src/Security/User.php
<?php
namespace App\Security;
class User implements JWTUserInterface
{
private int $customProp
public function getCustomProp() {
return $this->customProp;
}
...
}
But whenever I try to access the user in some service I do not get type hints for the customProp
// src/Service/MyService.php
<?php
namespace App\Service;
use Symfony\Component\Security\Core\Security;
class MyService
{
private int $customProp;
public function __construct(Security $security) {
$this->myCustomProp = $security->getUser()->getCustomProp();
} ~~~~~~~~~~~~~
}
The message I get is
Undefined method 'getCustomProp'.
But the value is there and the code works, I simply can not get the IDE to understand that my custom User class offers this method.