-
-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Psalm error for referenceRepository #424
Comments
You should show us the code of |
<?php
declare(strict_types=1);
namespace App\DataFixtures;
use App\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
class UserFixtures extends Fixture
{
public const USER_ADMIN = 'user-admin';
public const USER_MEMBER = 'user-member';
public function __construct(
private readonly UserPasswordHasherInterface $encoder
) {
}
public function load(ObjectManager $manager): void
{
$userAdmin = new User();
$userAdmin->setEmail('admin@test.de');
$userAdmin->setRoles(['ROLE_SUPER_ADMIN']);
$userAdmin->setLocale('de');
$userAdmin->setActive(true);
$userAdmin->setFullName('Test Admin User');
$userAdmin->setCreatedBy('fixture');
$userAdmin->setUpdatedBy('fixture');
$userAdmin->setPassword($this->encoder->hashPassword($userAdmin, '12345'));
$manager->persist($userAdmin);
$userMemeber = new User();
$userMemeber->setEmail('member@test.de');
$userMemeber->setRoles([]);
$userMemeber->setLocale('de');
$userMemeber->setActive(true);
$userMemeber->setFullName('Test Member User');
$userMemeber->setCreatedBy('fixture');
$userMemeber->setUpdatedBy('fixture');
$userMemeber->setPassword($this->encoder->hashPassword($userAdmin, '67890'));
$manager->persist($userMemeber);
$manager->flush();
$this->addReference(self::USER_ADMIN, $userAdmin);
$this->addReference(self::USER_MEMBER, $userMemeber);
}
} |
The AbstractFixture of class doctrine/data-fixture indeed does not set the The issue here is that Psalm rejects valid PHP code in order to avoid having to model the uninitialized state of PHP properties (PHP requires a property to be initialized at the time you use it, not at the end of the constructor) |
I think this should fix it: #425 |
i followed the example given here to inject a service into the fixture.
now when i'm running psalm it prints out a warning that
referenceRepository
is not set in the constructormy assumption is that it is because in
AbstractFixture
the type hint forreferenceRepository
only mentionsReferenceRepository
but not null which could theoretically happenThe text was updated successfully, but these errors were encountered: