mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge pull request #8770 from kenjis/fix-type-FabricatorModel
refactor: FabricatorModel
This commit is contained in:
commit
04394c6f0f
@ -8601,16 +8601,6 @@ $ignoreErrors[] = [
|
||||
'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 @@ $ignoreErrors[] = [
|
||||
'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,
|
||||
|
@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CodeIgniter\Test\Interfaces;
|
||||
|
||||
use CodeIgniter\BaseModel;
|
||||
use Faker\Generator;
|
||||
use ReflectionException;
|
||||
|
||||
@ -27,6 +28,8 @@ use ReflectionException;
|
||||
* @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<int|string>|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<row_array|object>)
|
||||
*/
|
||||
public function find($id = null);
|
||||
|
||||
@ -44,14 +47,15 @@ interface FabricatorModel
|
||||
* 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
|
||||
|
@ -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(),
|
||||
|
@ -6,5 +6,15 @@ use CodeIgniter\Test\Interfaces\FabricatorModel;
|
||||
|
||||
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.
|
||||
}
|
||||
|
||||
// ...
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user