Replies: 3 comments 2 replies
-
|
Please show some code that reports the error you're talking about. |
Beta Was this translation helpful? Give feedback.
-
|
case 1 use Symfony\Component\Security\Core\User\UserInterface;
class User implements UserInterface
{
/** @var non-empty-string */
private string $username;
public function setUsername(string $username): self
{
$this->username = mb_convert_case($username, MB_CASE_LOWER, mb_detect_encoding($username); // should return non-empty-string but returns string.
return $this;
}
/**
* @return non-empty-string
*/
public function getUserIdentifier(): string
{
return $this->username;
}
}case 2 use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Uid\Uuid;
class User implements UserInterface
{
/** @var non-empty-string */
private string $hash;
public function __construct()
{
$this->hash = Uuid::v4()->toRfc4122(); // $hash (non-empty-string) does not accept string.
}
/**
* @return non-empty-string
*/
public function getUserIdentifier(): string
{
return $this->hash;
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Case 1: We could add an extension for mb_convert_case which would understand this. This would be very similar to phpstan/phpstan-src#3549. Case 2: The best solution is to send a PR to Symfony to have |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How to explain to phpstan, that I want to use some external function for generating property that is returned by the getUserIdentifier() method in the constructor of the user entity, for example Symfony Uuid::v4()->toRfc4122(), which phpstan now throw an error: "(non-empty-string) does not accept string."?
The same story with mb_convert_case() function, which phpstan now throw the error "should return non-empty-string but returns string."
Beta Was this translation helpful? Give feedback.
All reactions