Skip to content

Commit

Permalink
refactor: change phpstan FactoryCollection return type (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil authored Dec 14, 2023
1 parent 531b30f commit 8a0f895
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
27 changes: 11 additions & 16 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ parameters:
count: 1
path: src/Factory.php

-
message: "#^Method Zenstruck\\\\Foundry\\\\FactoryCollection\\:\\:create\\(\\) should return array\\<int, TObject of object\\> but returns array\\<int, \\(TObject of object\\)\\|Zenstruck\\\\Foundry\\\\Persistence\\\\Proxy\\<TObject of object\\>\\>\\.$#"
count: 1
path: src/FactoryCollection.php

-
message: "#^Parameter \\#1 \\$min of function random_int expects int, int\\|null given\\.$#"
count: 1
Expand All @@ -36,24 +41,24 @@ parameters:
path: src/FactoryCollection.php

-
message: "#^Should not use function \"debug_backtrace\", please change the code\\.$#"
message: "#^Method Zenstruck\\\\Foundry\\\\Persistence\\\\PersistentObjectFactory\\:\\:__callStatic\\(\\) should return array\\<int, TModel of object\\> but returns array\\<int, \\(TModel of object\\)\\|Zenstruck\\\\Foundry\\\\Persistence\\\\Proxy\\<TModel of object\\>\\>\\.$#"
count: 1
path: src/Persistence/PersistentObjectFactory.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
message: "#^Method Zenstruck\\\\Foundry\\\\Persistence\\\\PersistentObjectFactory\\:\\:createSequence\\(\\) should return array\\<int, TModel of object\\> but returns array\\<int, \\(TModel of object\\)\\|Zenstruck\\\\Foundry\\\\Persistence\\\\Proxy\\<TModel of object\\>\\>\\.$#"
count: 1
path: src/Persistence/PersistentObjectFactory.php

-
message: "#^Method Zenstruck\\\\Foundry\\\\Persistence\\\\PersistentProxyObjectFactory\\:\\:__callStatic\\(\\) should return array\\<int, Zenstruck\\\\Foundry\\\\Persistence\\\\Proxy\\<TModel of object\\>\\> but returns array\\<int, \\(TModel of object\\)\\|Zenstruck\\\\Foundry\\\\Persistence\\\\Proxy\\<TModel of object\\>\\>\\.$#"
message: "#^Should not use function \"debug_backtrace\", please change the code\\.$#"
count: 1
path: src/Persistence/PersistentProxyObjectFactory.php
path: src/Persistence/PersistentObjectFactory.php

-
message: "#^Method Zenstruck\\\\Foundry\\\\Persistence\\\\PersistentProxyObjectFactory\\:\\:createSequence\\(\\) should return array\\<int, Zenstruck\\\\Foundry\\\\Persistence\\\\Proxy\\<TModel of object\\>\\> but returns array\\<int, \\(TModel of object\\)\\|Zenstruck\\\\Foundry\\\\Persistence\\\\Proxy\\<TModel of object\\>\\>\\.$#"
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Persistence/PersistentProxyObjectFactory.php
path: src/Persistence/PersistentObjectFactory.php

-
message: "#^Should not use function \"debug_backtrace\", please change the code\\.$#"
Expand Down Expand Up @@ -109,13 +114,3 @@ parameters:
message: "#^Parameter \\#1 \\$configuration of static method Zenstruck\\\\Foundry\\\\Factory\\<object\\>\\:\\:boot\\(\\) expects Zenstruck\\\\Foundry\\\\Configuration, object\\|null given\\.$#"
count: 1
path: src/ZenstruckFoundryBundle.php

-
message: "#^Function Zenstruck\\\\Foundry\\\\create_many\\(\\) should return array\\<int, Zenstruck\\\\Foundry\\\\Persistence\\\\Proxy\\<TObject of object\\>\\> but returns array\\<int, \\(TObject of object\\)\\|Zenstruck\\\\Foundry\\\\Persistence\\\\Proxy\\<TObject of object\\>\\>\\.$#"
count: 1
path: src/functions.php

-
message: "#^Function Zenstruck\\\\Foundry\\\\instantiate_many\\(\\) should return array\\<int, Zenstruck\\\\Foundry\\\\Persistence\\\\Proxy\\<TObject of object\\>\\> but returns array\\<int, \\(TObject of object\\)\\|Zenstruck\\\\Foundry\\\\Persistence\\\\Proxy\\<TObject of object\\>\\>\\.$#"
count: 1
path: src/functions.php
4 changes: 2 additions & 2 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function create(
/**
* @param int|null $max If set, when created, the collection will be a random size between $min and $max
*
* @return FactoryCollection<TObject>
* @return ($this is PersistentProxyObjectFactory ? FactoryCollection<Proxy<TObject>> : FactoryCollection<TObject>)
*/
final public function many(int $min, ?int $max = null): FactoryCollection
{
Expand All @@ -201,7 +201,7 @@ final public function many(int $min, ?int $max = null): FactoryCollection
/**
* @param iterable<array<string, mixed>>|callable(): iterable<array<string, mixed>> $sequence
*
* @return FactoryCollection<TObject>
* @return ($this is PersistentProxyObjectFactory ? FactoryCollection<Proxy<TObject>> : FactoryCollection<TObject>)
*/
final public function sequence(iterable|callable $sequence): FactoryCollection
{
Expand Down
4 changes: 1 addition & 3 deletions src/FactoryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ public static function sequence(Factory $factory, iterable $sequence): self
}

/**
* @return list<TObject&Proxy<TObject>>|list<TObject>
*
* @phpstan-return ($noProxy is true ? list<TObject>: list<Proxy<TObject>>|list<TObject>)
* @return list<TObject>
*/
public function create(
array|callable $attributes = [],
Expand Down

0 comments on commit 8a0f895

Please sign in to comment.