diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 48f7ddb49fe0..cfee07815e8a 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -8601,16 +8601,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Test/Fabricator.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Test\\\\Interfaces\\\\FabricatorModel\\:\\:find\\(\\) return type has no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Test/Interfaces/FabricatorModel.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Test\\\\Interfaces\\\\FabricatorModel\\:\\:insert\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Test/Interfaces/FabricatorModel.php', -]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\Test\\\\Mock\\\\MockBuilder\\:\\:\\$supportedIgnoreStatements type has no value type specified in iterable type array\\.$#', 'count' => 1, @@ -10386,11 +10376,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/_support/Models/EventModel.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Tests\\\\Support\\\\Models\\\\FabricatorModel\\:\\:fake\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/_support/Models/FabricatorModel.php', -]; $ignoreErrors[] = [ 'message' => '#^Property Tests\\\\Support\\\\Models\\\\JobModel\\:\\:\\$description has no type specified\\.$#', 'count' => 1, diff --git a/system/Test/Interfaces/FabricatorModel.php b/system/Test/Interfaces/FabricatorModel.php index d4a4c270919c..a5860e22fb83 100644 --- a/system/Test/Interfaces/FabricatorModel.php +++ b/system/Test/Interfaces/FabricatorModel.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Test\Interfaces; +use CodeIgniter\BaseModel; use Faker\Generator; use ReflectionException; @@ -27,6 +28,8 @@ * @property string $returnType * @property string $primaryKey * @property string $dateFormat + * + * @phpstan-import-type row_array from BaseModel */ interface FabricatorModel { @@ -34,9 +37,9 @@ interface FabricatorModel * Fetches the row of database from $this->table with a primary key * matching $id. * - * @param array|mixed|null $id One primary key or an array of primary keys + * @param int|list|string|null $id One primary key or an array of primary keys * - * @return array|object|null The resulting row of data, or null. + * @phpstan-return ($id is int|string ? row_array|object|null : list) */ public function find($id = null); @@ -44,14 +47,15 @@ public function find($id = null); * Inserts data into the current table. If an object is provided, * it will attempt to convert it to an array. * - * @param array|object $data - * @param bool $returnID Whether insert ID should be returned or not. + * @param array|object|null $row + * @phpstan-param row_array|object|null $row + * @param bool $returnID Whether insert ID should be returned or not. * * @return bool|int|string * * @throws ReflectionException */ - public function insert($data = null, bool $returnID = true); + public function insert($row = null, bool $returnID = true); /** * The following properties and methods are optional, but if present should diff --git a/tests/_support/Models/FabricatorModel.php b/tests/_support/Models/FabricatorModel.php index 2903b5036402..1cae9394b9a3 100644 --- a/tests/_support/Models/FabricatorModel.php +++ b/tests/_support/Models/FabricatorModel.php @@ -28,8 +28,10 @@ class FabricatorModel extends Model 'description', ]; - // Return a faked entity - public function fake(Generator &$faker) + /** + * Return a faked entity + */ + public function fake(Generator &$faker): object { return (object) [ 'name' => $faker->ipv4(), diff --git a/user_guide_src/source/testing/fabricator/001.php b/user_guide_src/source/testing/fabricator/001.php index 8fbf136032ca..f237d56b1324 100644 --- a/user_guide_src/source/testing/fabricator/001.php +++ b/user_guide_src/source/testing/fabricator/001.php @@ -6,5 +6,15 @@ class MyModel implements FabricatorModel { + public function find($id = null) + { + // TODO: Implement find() method. + } + + public function insert($row = null, bool $returnID = true) + { + // TODO: Implement insert() method. + } + // ... }