I know that I can use this encoder:
$encoder = $this->container->get('security.password_encoder');
$encoded = $encoder->encodePassword($user, $plainPassword);
But when I should use it? I can encode password before calling setPassword() method. Or I can encode password in setPassword() method. Or maybe I should create a custom doctrine data type which will encode password before save to database? Or something else? Which variant is better?