Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9621dae

Browse files
Improve phpdoc for non empty list (#1037)
1 parent 4ab260d commit 9621dae

10 files changed

Lines changed: 37 additions & 30 deletions

src/Factory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static function createOne(array|callable $attributes = []): mixed
7070
* @phpstan-param Attributes $attributes
7171
*
7272
* @return list<T>
73+
* @phpstan-return ($number is positive-int ? non-empty-list<T> : list<T>)
7374
*/
7475
final public static function createMany(int $number, array|callable $attributes = []): array
7576
{
@@ -80,6 +81,7 @@ final public static function createMany(int $number, array|callable $attributes
8081
* @phpstan-param Attributes $attributes
8182
*
8283
* @return list<T>
84+
* @phpstan-return ($min is positive-int ? non-empty-list<T> : list<T>)
8385
*/
8486
final public static function createRange(int $min, int $max, array|callable $attributes = []): array
8587
{

src/Persistence/PersistentObjectFactory.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public static function randomOrCreate(array $criteria = []): object
100100

101101
/**
102102
* @param positive-int $count
103-
* @phpstan-param Parameters $criteria
103+
* @phpstan-param Parameters $criteria
104104
*
105-
* @return list<T>
105+
* @return non-empty-list<T>
106106
*/
107107
public static function randomSet(int $count, array $criteria = []): array
108108
{
@@ -112,9 +112,10 @@ public static function randomSet(int $count, array $criteria = []): array
112112
/**
113113
* @param int<0, max> $min
114114
* @param int<0, max> $max
115-
* @phpstan-param Parameters $criteria
115+
* @phpstan-param Parameters $criteria
116116
*
117117
* @return list<T>
118+
* @phpstan-return ($min is positive-int ? non-empty-list<T> : list<T>)
118119
*/
119120
public static function randomRange(int $min, int $max, array $criteria = []): array
120121
{
@@ -124,9 +125,10 @@ public static function randomRange(int $min, int $max, array $criteria = []): ar
124125
/**
125126
* @param int<0, max> $min
126127
* @param int<0, max> $max
127-
* @phpstan-param Parameters $criteria
128+
* @phpstan-param Parameters $criteria
128129
*
129130
* @return list<T>
131+
* @phpstan-return ($min is positive-int ? non-empty-list<T> : list<T>)
130132
*/
131133
public static function randomRangeOrCreate(int $min, int $max, array $criteria = []): array
132134
{

src/Persistence/PersistentProxyObjectFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ final public static function randomOrCreate(array $criteria = []): object
8989
}
9090

9191
/**
92-
* @return list<T&Proxy<T>>
92+
* @return non-empty-list<T&Proxy<T>>
9393
*/
9494
final public static function randomSet(int $count, array $criteria = []): array
9595
{
@@ -98,6 +98,7 @@ final public static function randomSet(int $count, array $criteria = []): array
9898

9999
/**
100100
* @return list<T&Proxy<T>>
101+
* @phpstan-return ($min is positive-int ? non-empty-list<T&Proxy<T>> : list<T&Proxy<T>>)
101102
*/
102103
final public static function randomRange(int $min, int $max, array $criteria = []): array
103104
{
@@ -106,6 +107,7 @@ final public static function randomRange(int $min, int $max, array $criteria = [
106107

107108
/**
108109
* @return list<T&Proxy<T>>
110+
* @phpstan-return ($min is positive-int ? non-empty-list<T&Proxy<T>> : list<T&Proxy<T>>)
109111
*/
110112
public static function randomRangeOrCreate(int $min, int $max, array $criteria = []): array
111113
{

src/Persistence/RepositoryDecorator.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ public function random(array $criteria = []): object
204204

205205
/**
206206
* @param positive-int $count
207-
* @phpstan-param Parameters $criteria
207+
* @phpstan-param Parameters $criteria
208208
*
209-
* @return list<T>
209+
* @return non-empty-list<T>
210210
*/
211211
public function randomSet(int $count, array $criteria = []): array
212212
{
@@ -220,9 +220,10 @@ public function randomSet(int $count, array $criteria = []): array
220220
/**
221221
* @param int<0, max> $min
222222
* @param int<0, max> $max
223-
* @phpstan-param Parameters $criteria
223+
* @phpstan-param Parameters $criteria
224224
*
225225
* @return list<T>
226+
* @phpstan-return ($min is positive-int ? non-empty-list<T> : list<T>)
226227
*/
227228
public function randomRange(int $min, int $max, array $criteria = []): array
228229
{

stubs/phpstan/ObjectFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ protected function defaults(): array
4444
assertType('UserForObjectFactory', UserObjectFactory::new()->with()->create());
4545

4646
// methods returning a list of objects
47-
assertType("list<UserForObjectFactory>", UserObjectFactory::createMany(1));
48-
assertType("list<UserForObjectFactory>", UserObjectFactory::createRange(1, 2));
47+
assertType("non-empty-list<UserForObjectFactory>", UserObjectFactory::createMany(1));
48+
assertType("non-empty-list<UserForObjectFactory>", UserObjectFactory::createRange(1, 2));
4949
assertType("list<UserForObjectFactory>", UserObjectFactory::createSequence([]));
5050

5151
// methods with FactoryCollection

stubs/phpstan/PersistentObjectFactory.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ protected function defaults(): array
4747

4848
// methods returning a list of objects
4949
assertType("list<UserForPersistentFactory>", UserFactory::all());
50-
assertType("list<UserForPersistentFactory>", UserFactory::createMany(1));
51-
assertType("list<UserForPersistentFactory>", UserFactory::createRange(1, 2));
50+
assertType("non-empty-list<UserForPersistentFactory>", UserFactory::createMany(1));
51+
assertType("non-empty-list<UserForPersistentFactory>", UserFactory::createRange(1, 2));
5252
assertType("list<UserForPersistentFactory>", UserFactory::createSequence([]));
53-
assertType("list<UserForPersistentFactory>", UserFactory::randomRange(1, 2));
54-
assertType("list<UserForPersistentFactory>", UserFactory::randomSet(2));
53+
assertType("non-empty-list<UserForPersistentFactory>", UserFactory::randomRange(1, 2));
54+
assertType("non-empty-list<UserForPersistentFactory>", UserFactory::randomSet(2));
5555
assertType("list<UserForPersistentFactory>", UserFactory::findBy(['name' => 'foo']));
5656

5757
// methods with FactoryCollection
@@ -78,8 +78,8 @@ protected function defaults(): array
7878
assertType('UserForPersistentFactory', $repository->random());
7979
assertType("list<UserForPersistentFactory>", $repository->findAll());
8080
assertType("list<UserForPersistentFactory>", $repository->findBy([]));
81-
assertType("list<UserForPersistentFactory>", $repository->randomSet(2));
82-
assertType("list<UserForPersistentFactory>", $repository->randomRange(1, 2));
81+
assertType("non-empty-list<UserForPersistentFactory>", $repository->randomSet(2));
82+
assertType("non-empty-list<UserForPersistentFactory>", $repository->randomRange(1, 2));
8383
assertType('int<0, max>', $repository->count());
8484

8585
// test autocomplete with phpstorm

stubs/phpstan/PersistentProxyObjectFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ protected function defaults(): array
4848

4949
// methods returning a list of objects
5050
assertType("list<{$proxyType}>", UserProxyFactory::all());
51-
assertType("list<{$proxyType}>", UserProxyFactory::createMany(1));
52-
assertType("list<{$proxyType}>", UserProxyFactory::createRange(1, 2));
51+
assertType("non-empty-list<{$proxyType}>", UserProxyFactory::createMany(1));
52+
assertType("non-empty-list<{$proxyType}>", UserProxyFactory::createRange(1, 2));
5353
assertType("list<{$proxyType}>", UserProxyFactory::createSequence([]));
54-
assertType("list<{$proxyType}>", UserProxyFactory::randomRange(1, 2));
55-
assertType("list<{$proxyType}>", UserProxyFactory::randomRangeOrCreate(1, 2));
56-
assertType("list<{$proxyType}>", UserProxyFactory::randomSet(2));
54+
assertType("non-empty-list<{$proxyType}>", UserProxyFactory::randomRange(1, 2));
55+
assertType("non-empty-list<{$proxyType}>", UserProxyFactory::randomRangeOrCreate(1, 2));
56+
assertType("non-empty-list<{$proxyType}>", UserProxyFactory::randomSet(2));
5757
assertType("list<{$proxyType}>", UserProxyFactory::findBy(['name' => 'foo']));
5858

5959
// methods with FactoryCollection

stubs/psalm/ObjectFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ protected function defaults(): array|callable
4343
$var = UserObjectFactory::new()->with()->create();
4444

4545
// methods returning a list of objects
46-
/** @psalm-check-type-exact $var = list<UserForObjectFactory> */
46+
/** @psalm-check-type-exact $var = non-empty-list<UserForObjectFactory> */
4747
$var = UserObjectFactory::createMany(1);
48-
/** @psalm-check-type-exact $var = list<UserForObjectFactory> */
48+
/** @psalm-check-type-exact $var = non-empty-list<UserForObjectFactory> */
4949
$var = UserObjectFactory::createRange(1, 2);
5050
/** @psalm-check-type-exact $var = list<UserForObjectFactory> */
5151
$var = UserObjectFactory::createSequence([]);

stubs/psalm/PersistentObjectFactory.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ protected function defaults(): array|callable
5757
// methods returning a list of objects
5858
/** @psalm-check-type-exact $var = list<UserForPersistentFactory> */
5959
$var = UserFactory::all();
60-
/** @psalm-check-type-exact $var = list<UserForPersistentFactory> */
60+
/** @psalm-check-type-exact $var = non-empty-list<UserForPersistentFactory> */
6161
$var = UserFactory::createMany(1);
62-
/** @psalm-check-type-exact $var = list<UserForPersistentFactory> */
62+
/** @psalm-check-type-exact $var = non-empty-list<UserForPersistentFactory> */
6363
$var = UserFactory::createRange(1, 2);
6464
/** @psalm-check-type-exact $var = list<UserForPersistentFactory> */
6565
$var = UserFactory::createSequence([]);
66-
/** @psalm-check-type-exact $var = list<UserForPersistentFactory> */
66+
/** @psalm-check-type-exact $var = non-empty-list<UserForPersistentFactory> */
6767
$var = UserFactory::randomRange(1, 2);
68-
/** @psalm-check-type-exact $var = list<UserForPersistentFactory> */
68+
/** @psalm-check-type-exact $var = non-empty-list<UserForPersistentFactory> */
6969
$var = UserFactory::randomSet(2);
7070
/** @psalm-check-type-exact $var = list<UserForPersistentFactory> */
7171
$var = UserFactory::findBy(['name' => 'foo']);
@@ -110,9 +110,9 @@ protected function defaults(): array|callable
110110
$var = $repository->findAll();
111111
/** @psalm-check-type-exact $var = list<UserForPersistentFactory> */
112112
$var = $repository->findBy([]);
113-
/** @psalm-check-type-exact $var = list<UserForPersistentFactory> */
113+
/** @psalm-check-type-exact $var = non-empty-list<UserForPersistentFactory> */
114114
$var = $repository->randomSet(2);
115-
/** @psalm-check-type-exact $var = list<UserForPersistentFactory> */
115+
/** @psalm-check-type-exact $var = non-empty-list<UserForPersistentFactory> */
116116
$var = $repository->randomRange(1, 2);
117117
/** @psalm-check-type-exact $var = int */
118118
$var = $repository->count();

stubs/psalm/PersistentProxyObjectFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function defaults(): array|callable
6565
$var = UserProxyFactory::createSequence([]);
6666
/** @psalm-check-type-exact $var = list<UserForProxyFactory&Proxy<UserForProxyFactory>> */
6767
$var = UserProxyFactory::randomRange(1, 2);
68-
/** @psalm-check-type-exact $var = list<UserForProxyFactory&Proxy<UserForProxyFactory>> */
68+
/** @psalm-check-type-exact $var = non-empty-list<UserForProxyFactory&Proxy<UserForProxyFactory>> */
6969
$var = UserProxyFactory::randomRangeOrCreate(1, 2);
7070
/** @psalm-check-type-exact $var = list<UserForProxyFactory&Proxy<UserForProxyFactory>> */
7171
$var = UserProxyFactory::randomSet(2);

0 commit comments

Comments
 (0)