diff --git a/src/Factory.php b/src/Factory.php index aea1a2cc4..e22cc3a0f 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -70,6 +70,7 @@ public static function createOne(array|callable $attributes = []): mixed * @phpstan-param Attributes $attributes * * @return list + * @phpstan-return ($number is positive-int ? non-empty-list : list) */ final public static function createMany(int $number, array|callable $attributes = []): array { @@ -80,6 +81,7 @@ final public static function createMany(int $number, array|callable $attributes * @phpstan-param Attributes $attributes * * @return list + * @phpstan-return ($min is positive-int ? non-empty-list : list) */ final public static function createRange(int $min, int $max, array|callable $attributes = []): array { diff --git a/src/Persistence/PersistentObjectFactory.php b/src/Persistence/PersistentObjectFactory.php index 8a7b8d6c2..1fdaec66d 100644 --- a/src/Persistence/PersistentObjectFactory.php +++ b/src/Persistence/PersistentObjectFactory.php @@ -100,9 +100,9 @@ public static function randomOrCreate(array $criteria = []): object /** * @param positive-int $count - * @phpstan-param Parameters $criteria + * @phpstan-param Parameters $criteria * - * @return list + * @return non-empty-list */ public static function randomSet(int $count, array $criteria = []): array { @@ -112,9 +112,10 @@ public static function randomSet(int $count, array $criteria = []): array /** * @param int<0, max> $min * @param int<0, max> $max - * @phpstan-param Parameters $criteria + * @phpstan-param Parameters $criteria * * @return list + * @phpstan-return ($min is positive-int ? non-empty-list : list) */ public static function randomRange(int $min, int $max, array $criteria = []): array { @@ -124,9 +125,10 @@ public static function randomRange(int $min, int $max, array $criteria = []): ar /** * @param int<0, max> $min * @param int<0, max> $max - * @phpstan-param Parameters $criteria + * @phpstan-param Parameters $criteria * * @return list + * @phpstan-return ($min is positive-int ? non-empty-list : list) */ public static function randomRangeOrCreate(int $min, int $max, array $criteria = []): array { diff --git a/src/Persistence/PersistentProxyObjectFactory.php b/src/Persistence/PersistentProxyObjectFactory.php index e51d80a75..00001d023 100644 --- a/src/Persistence/PersistentProxyObjectFactory.php +++ b/src/Persistence/PersistentProxyObjectFactory.php @@ -89,7 +89,7 @@ final public static function randomOrCreate(array $criteria = []): object } /** - * @return list> + * @return non-empty-list> */ final public static function randomSet(int $count, array $criteria = []): array { @@ -98,6 +98,7 @@ final public static function randomSet(int $count, array $criteria = []): array /** * @return list> + * @phpstan-return ($min is positive-int ? non-empty-list> : list>) */ final public static function randomRange(int $min, int $max, array $criteria = []): array { @@ -106,6 +107,7 @@ final public static function randomRange(int $min, int $max, array $criteria = [ /** * @return list> + * @phpstan-return ($min is positive-int ? non-empty-list> : list>) */ public static function randomRangeOrCreate(int $min, int $max, array $criteria = []): array { diff --git a/src/Persistence/RepositoryDecorator.php b/src/Persistence/RepositoryDecorator.php index b5d2097cd..3764f5fab 100644 --- a/src/Persistence/RepositoryDecorator.php +++ b/src/Persistence/RepositoryDecorator.php @@ -204,9 +204,9 @@ public function random(array $criteria = []): object /** * @param positive-int $count - * @phpstan-param Parameters $criteria + * @phpstan-param Parameters $criteria * - * @return list + * @return non-empty-list */ public function randomSet(int $count, array $criteria = []): array { @@ -220,9 +220,10 @@ public function randomSet(int $count, array $criteria = []): array /** * @param int<0, max> $min * @param int<0, max> $max - * @phpstan-param Parameters $criteria + * @phpstan-param Parameters $criteria * * @return list + * @phpstan-return ($min is positive-int ? non-empty-list : list) */ public function randomRange(int $min, int $max, array $criteria = []): array { diff --git a/stubs/phpstan/ObjectFactory.php b/stubs/phpstan/ObjectFactory.php index 5949e9716..7113fd939 100644 --- a/stubs/phpstan/ObjectFactory.php +++ b/stubs/phpstan/ObjectFactory.php @@ -44,8 +44,8 @@ protected function defaults(): array assertType('UserForObjectFactory', UserObjectFactory::new()->with()->create()); // methods returning a list of objects -assertType("list", UserObjectFactory::createMany(1)); -assertType("list", UserObjectFactory::createRange(1, 2)); +assertType("non-empty-list", UserObjectFactory::createMany(1)); +assertType("non-empty-list", UserObjectFactory::createRange(1, 2)); assertType("list", UserObjectFactory::createSequence([])); // methods with FactoryCollection diff --git a/stubs/phpstan/PersistentObjectFactory.php b/stubs/phpstan/PersistentObjectFactory.php index f01610067..16d64832f 100644 --- a/stubs/phpstan/PersistentObjectFactory.php +++ b/stubs/phpstan/PersistentObjectFactory.php @@ -47,11 +47,11 @@ protected function defaults(): array // methods returning a list of objects assertType("list", UserFactory::all()); -assertType("list", UserFactory::createMany(1)); -assertType("list", UserFactory::createRange(1, 2)); +assertType("non-empty-list", UserFactory::createMany(1)); +assertType("non-empty-list", UserFactory::createRange(1, 2)); assertType("list", UserFactory::createSequence([])); -assertType("list", UserFactory::randomRange(1, 2)); -assertType("list", UserFactory::randomSet(2)); +assertType("non-empty-list", UserFactory::randomRange(1, 2)); +assertType("non-empty-list", UserFactory::randomSet(2)); assertType("list", UserFactory::findBy(['name' => 'foo'])); // methods with FactoryCollection @@ -78,8 +78,8 @@ protected function defaults(): array assertType('UserForPersistentFactory', $repository->random()); assertType("list", $repository->findAll()); assertType("list", $repository->findBy([])); -assertType("list", $repository->randomSet(2)); -assertType("list", $repository->randomRange(1, 2)); +assertType("non-empty-list", $repository->randomSet(2)); +assertType("non-empty-list", $repository->randomRange(1, 2)); assertType('int<0, max>', $repository->count()); // test autocomplete with phpstorm diff --git a/stubs/phpstan/PersistentProxyObjectFactory.php b/stubs/phpstan/PersistentProxyObjectFactory.php index 5b5ad5206..90ccea7f2 100644 --- a/stubs/phpstan/PersistentProxyObjectFactory.php +++ b/stubs/phpstan/PersistentProxyObjectFactory.php @@ -48,12 +48,12 @@ protected function defaults(): array // methods returning a list of objects assertType("list<{$proxyType}>", UserProxyFactory::all()); -assertType("list<{$proxyType}>", UserProxyFactory::createMany(1)); -assertType("list<{$proxyType}>", UserProxyFactory::createRange(1, 2)); +assertType("non-empty-list<{$proxyType}>", UserProxyFactory::createMany(1)); +assertType("non-empty-list<{$proxyType}>", UserProxyFactory::createRange(1, 2)); assertType("list<{$proxyType}>", UserProxyFactory::createSequence([])); -assertType("list<{$proxyType}>", UserProxyFactory::randomRange(1, 2)); -assertType("list<{$proxyType}>", UserProxyFactory::randomRangeOrCreate(1, 2)); -assertType("list<{$proxyType}>", UserProxyFactory::randomSet(2)); +assertType("non-empty-list<{$proxyType}>", UserProxyFactory::randomRange(1, 2)); +assertType("non-empty-list<{$proxyType}>", UserProxyFactory::randomRangeOrCreate(1, 2)); +assertType("non-empty-list<{$proxyType}>", UserProxyFactory::randomSet(2)); assertType("list<{$proxyType}>", UserProxyFactory::findBy(['name' => 'foo'])); // methods with FactoryCollection diff --git a/stubs/psalm/ObjectFactory.php b/stubs/psalm/ObjectFactory.php index 71de6f8eb..4a8f0d159 100644 --- a/stubs/psalm/ObjectFactory.php +++ b/stubs/psalm/ObjectFactory.php @@ -43,9 +43,9 @@ protected function defaults(): array|callable $var = UserObjectFactory::new()->with()->create(); // methods returning a list of objects -/** @psalm-check-type-exact $var = list */ +/** @psalm-check-type-exact $var = non-empty-list */ $var = UserObjectFactory::createMany(1); -/** @psalm-check-type-exact $var = list */ +/** @psalm-check-type-exact $var = non-empty-list */ $var = UserObjectFactory::createRange(1, 2); /** @psalm-check-type-exact $var = list */ $var = UserObjectFactory::createSequence([]); diff --git a/stubs/psalm/PersistentObjectFactory.php b/stubs/psalm/PersistentObjectFactory.php index 5446baab7..8f1f51bd3 100644 --- a/stubs/psalm/PersistentObjectFactory.php +++ b/stubs/psalm/PersistentObjectFactory.php @@ -57,15 +57,15 @@ protected function defaults(): array|callable // methods returning a list of objects /** @psalm-check-type-exact $var = list */ $var = UserFactory::all(); -/** @psalm-check-type-exact $var = list */ +/** @psalm-check-type-exact $var = non-empty-list */ $var = UserFactory::createMany(1); -/** @psalm-check-type-exact $var = list */ +/** @psalm-check-type-exact $var = non-empty-list */ $var = UserFactory::createRange(1, 2); /** @psalm-check-type-exact $var = list */ $var = UserFactory::createSequence([]); -/** @psalm-check-type-exact $var = list */ +/** @psalm-check-type-exact $var = non-empty-list */ $var = UserFactory::randomRange(1, 2); -/** @psalm-check-type-exact $var = list */ +/** @psalm-check-type-exact $var = non-empty-list */ $var = UserFactory::randomSet(2); /** @psalm-check-type-exact $var = list */ $var = UserFactory::findBy(['name' => 'foo']); @@ -110,9 +110,9 @@ protected function defaults(): array|callable $var = $repository->findAll(); /** @psalm-check-type-exact $var = list */ $var = $repository->findBy([]); -/** @psalm-check-type-exact $var = list */ +/** @psalm-check-type-exact $var = non-empty-list */ $var = $repository->randomSet(2); -/** @psalm-check-type-exact $var = list */ +/** @psalm-check-type-exact $var = non-empty-list */ $var = $repository->randomRange(1, 2); /** @psalm-check-type-exact $var = int */ $var = $repository->count(); diff --git a/stubs/psalm/PersistentProxyObjectFactory.php b/stubs/psalm/PersistentProxyObjectFactory.php index d9592add5..8e6601d91 100644 --- a/stubs/psalm/PersistentProxyObjectFactory.php +++ b/stubs/psalm/PersistentProxyObjectFactory.php @@ -65,7 +65,7 @@ protected function defaults(): array|callable $var = UserProxyFactory::createSequence([]); /** @psalm-check-type-exact $var = list> */ $var = UserProxyFactory::randomRange(1, 2); -/** @psalm-check-type-exact $var = list> */ +/** @psalm-check-type-exact $var = non-empty-list> */ $var = UserProxyFactory::randomRangeOrCreate(1, 2); /** @psalm-check-type-exact $var = list> */ $var = UserProxyFactory::randomSet(2);