diff --git a/src/Persistence/PersistentObjectFactory.php b/src/Persistence/PersistentObjectFactory.php index 63f723d5..eb43ba23 100644 --- a/src/Persistence/PersistentObjectFactory.php +++ b/src/Persistence/PersistentObjectFactory.php @@ -182,7 +182,9 @@ public static function repository(): ObjectRepository { Configuration::instance()->assertPersistanceEnabled(); - return new RepositoryDecorator(static::class()); // @phpstan-ignore-line + return is_a(static::class, PersistentProxyObjectFactory::class, allow_string: true) // @phpstan-ignore return.type + ? new ProxyRepositoryDecorator(static::class()) // @phpstan-ignore argument.type + : new RepositoryDecorator(static::class()); } final public static function assert(): RepositoryAssertions diff --git a/src/Persistence/PersistentProxyObjectFactory.php b/src/Persistence/PersistentProxyObjectFactory.php index a8b4870c..8175afff 100644 --- a/src/Persistence/PersistentProxyObjectFactory.php +++ b/src/Persistence/PersistentProxyObjectFactory.php @@ -11,35 +11,11 @@ namespace Zenstruck\Foundry\Persistence; -use Doctrine\Persistence\ObjectRepository; -use Zenstruck\Foundry\Configuration; -use Zenstruck\Foundry\Factory; -use Zenstruck\Foundry\Object\Instantiator; -use Zenstruck\Foundry\FactoryCollection; // keep me! - /** * @author Kevin Bond * * @template T of object * @extends PersistentObjectFactory> - * - * @phpstan-type InstantiatorCallable = Instantiator|callable(Parameters,class-string):T - * @phpstan-import-type Parameters from Factory - * @phpstan-import-type Attributes from Factory - * - * @phpstan-method $this instantiateWith(InstantiatorCallable $instantiator) - * - * @phpstan-method FactoryCollection> sequence(iterable>|callable(): iterable> $sequence) - * @phpstan-method FactoryCollection> many(int $min, int|null $max = null) - * - * @phpstan-method static list> createSequence(iterable>|callable(): iterable> $sequence) - * @phpstan-method static list> createMany(int $number, array|callable $attributes = []) - * - * @method static Proxy createOne(Attributes $attributes = []) - * @phpstan-method static T&Proxy createOne(Attributes $attributes = []) - * - * @method Proxy create(Attributes $attributes = []) - * @phpstan-method T&Proxy create(Attributes $attributes = []) */ abstract class PersistentProxyObjectFactory extends PersistentObjectFactory { @@ -47,100 +23,4 @@ abstract class PersistentProxyObjectFactory extends PersistentObjectFactory * @return class-string */ abstract public static function class(): string; - - /** - * @return Proxy - * @phpstan-return T&Proxy - */ - final public static function find(mixed $criteriaOrId): object - { - return proxy(parent::find($criteriaOrId)); // @phpstan-ignore-line - } - - /** - * @return Proxy - * @phpstan-return T&Proxy - */ - final public static function findOrCreate(array $criteria): object - { - return proxy(parent::findOrCreate($criteria)); // @phpstan-ignore-line - } - - /** - * @return Proxy - * @phpstan-return T&Proxy - */ - final public static function randomOrCreate(array $criteria = []): object - { - return proxy(parent::randomOrCreate($criteria)); // @phpstan-ignore-line - } - - /** - * @return list> - */ - final public static function randomSet(int $count, array $criteria = []): array - { - return \array_map(proxy(...), parent::randomSet($count, $criteria)); // @phpstan-ignore-line - } - - /** - * @return list> - */ - final public static function randomRange(int $min, int $max, array $criteria = []): array - { - return \array_map(proxy(...), parent::randomRange($min, $max, $criteria)); // @phpstan-ignore-line - } - - /** - * @return list> - */ - final public static function findBy(array $criteria): array - { - return \array_map(proxy(...), parent::findBy($criteria)); // @phpstan-ignore-line - } - - /** - * @return Proxy - * @phpstan-return T&Proxy - */ - final public static function random(array $criteria = []): object - { - return proxy(parent::random($criteria)); // @phpstan-ignore-line - } - - /** - * @return Proxy - * @phpstan-return T&Proxy - */ - final public static function first(string $sortBy = 'id'): object - { - return proxy(parent::first($sortBy)); // @phpstan-ignore-line - } - - /** - * @return Proxy - * @phpstan-return T&Proxy - */ - final public static function last(string $sortBy = 'id'): object - { - return proxy(parent::last($sortBy)); // @phpstan-ignore-line - } - - /** - * @return list> - */ - final public static function all(): array - { - return \array_map(proxy(...), parent::all()); // @phpstan-ignore-line - } - - /** - * @return ProxyRepositoryDecorator> - */ - final public static function repository(): ObjectRepository - { - Configuration::instance()->assertPersistanceEnabled(); - - return new ProxyRepositoryDecorator(static::class()); // @phpstan-ignore-line - } }