Repository: doctrine/data-fixtures (language: php)

Issue:
Psalm error for referenceRepository
i followed the example given [here](https://symfony.com/bundles/DoctrineFixturesBundle/current/index.html#accessing-services-from-the-fixtures) 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 constructor

```
ERROR: PropertyNotSetInConstructor - src/DataFixtures/UserFixtures.php:12:7 - Property App\DataFixtures\UserFixtures::$referenceRepository is not defined in constructor of App\DataFixtures\UserFixtures or in any methods called in the constructor (see https://psalm.dev/074)
class UserFixtures extends Fixture
```

my assumption is that it is because in `AbstractFixture` the type hint for `referenceRepository` only mentions `ReferenceRepository` but not null which could theoretically happen



Discussion / hints:
You should show us the code of `UserFixtures.php`. There is no occurrence of `referenceRepository` in the page you linked.
```php
<?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 `referenceRepository` property in the constructor. However, it does set it through the setter before usage.

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)

Fix patch:
diff --git a/src/AbstractFixture.php b/src/AbstractFixture.php
index e47adec7..7d50a2f5 100644
--- a/src/AbstractFixture.php
+++ b/src/AbstractFixture.php
@@ -7,6 +7,8 @@
 use BadMethodCallException;
 use Doctrine\Deprecations\Deprecation;
 
+use function assert;
+
 /**
  * Abstract Fixture class helps to manage references
  * between fixture classes in order to set relations
@@ -17,7 +19,7 @@ abstract class AbstractFixture implements SharedFixtureInterface
     /**
      * Fixture reference repository
      *
-     * @var ReferenceRepository
+     * @var ReferenceRepository|null
      */
     protected $referenceRepository;
 
@@ -29,6 +31,13 @@ public function setReferenceRepository(ReferenceRepository $referenceRepository)
         $this->referenceRepository = $referenceRepository;
     }
 
+    private function getReferenceRepository(): ReferenceRepository
+    {
+        assert($this->referenceRepository !== null);
+
+        return $this->referenceRepository;
+    }
+
     /**
      * Set the reference entry identified by $name
      * and referenced to managed $object. If $name
@@ -43,7 +52,7 @@ public function setReferenceRepository(ReferenceRepository $referenceRepository)
      */
     public function setReference($name, $object)
     {
-        $this->referenceRepository->setReference($name, $object);
+        $this->getReferenceRepository()->setReference($name, $object);
     }
 
     /**
@@ -63,7 +72,7 @@ public function setReference($name, $object)
      */
     public function addReference($name, $object)
     {
-        $this->referenceRepository->addReference($name, $object);
+        $this->getReferenceRepository()->addReference($name, $object);
     }
 
     /**
@@ -91,7 +100,7 @@ public function getReference($name, ?string $class = null)
             );
         }
 
-        return $this->referenceRepository->getReference($name, $class);
+        return $this->getReferenceRepository()->getReference($name, $class);
     }
 
     /**
@@ -116,6 +125,6 @@ public function hasReference($name, ?string $class = null)
             );
         }
 
-        return $this->referenceRepository->hasReference($name, $class);
+        return $this->getReferenceRepository()->hasReference($name, $class);
     }
 }


Test patch: