Skip to content

Commit a5ecd16

Browse files
committed
docs: add types for PHPStan
1 parent 36e555c commit a5ecd16

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

system/BaseModel.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
* - ensure validation is run against objects when saving items
4242
* - process various callbacks
4343
* - allow intermingling calls to the db connection
44+
*
45+
* @phpstan-type RowArray array<int|string, float|int|null|string>
46+
* @phpstan-type EventDataBeforeInsert array{data: RowArray}
47+
* @phpstan-type EventDataAfterInsert array{id: int|string, data: RowArray, result: bool}
48+
* @phpstan-type EventDataBeforeFind array{id?: int|string, method: string, singleton: bool, limit?: int, offset?: int}
49+
* @phpstan-type EventDataAfterFind array{id: int|string|null|list<int|string>, data: RowArray|list<RowArray>|object|null, method: string, singleton: bool}
50+
* @phpstan-type EventDataBeforeUpdate array{id: null|list<int|string>, data: RowArray}
51+
* @phpstan-type EventDataAfterUpdate array{id: null|list<int|string>, data: RowArray|object, result: bool}
52+
* @phpstan-type EventDataBeforeDelete array{id: null|list<int|string>, purge: bool}
53+
* @phpstan-type EventDataAfterDelete array{id: null|list<int|string>, data: null, purge: bool, result: bool}
4454
*/
4555
abstract class BaseModel
4656
{
@@ -539,6 +549,7 @@ abstract public function chunk(int $size, Closure $userFunc);
539549
* @param array|int|string|null $id One primary key or an array of primary keys
540550
*
541551
* @return array|object|null The resulting row of data, or null.
552+
* @phpstan-return ($id is int|string ? RowArray|object|null : list<RowArray|object>)
542553
*/
543554
public function find($id = null)
544555
{

system/Model.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
* @method $this where($key, $value = null, ?bool $escape = null)
8585
* @method $this whereIn(?string $key = null, $values = null, ?bool $escape = null)
8686
* @method $this whereNotIn(?string $key = null, $values = null, ?bool $escape = null)
87+
*
88+
* @phpstan-import-type RowArray from \CodeIgniter\BaseModel
8789
*/
8890
class Model extends BaseModel
8991
{
@@ -178,6 +180,7 @@ public function setTable(string $table)
178180
* @param array|int|string|null $id One primary key or an array of primary keys
179181
*
180182
* @return array|object|null The resulting row of data, or null.
183+
* @phpstan-return ($singleton is true ? RowArray|null|object : list<RowArray|object>)
181184
*/
182185
protected function doFind(bool $singleton, $id = null)
183186
{
@@ -224,6 +227,7 @@ protected function doFindColumn(string $columnName)
224227
* @param int $offset Offset
225228
*
226229
* @return array
230+
* @phpstan-return list<RowArray|object>
227231
*/
228232
protected function doFindAll(int $limit = 0, int $offset = 0)
229233
{
@@ -244,6 +248,7 @@ protected function doFindAll(int $limit = 0, int $offset = 0)
244248
* This method works only with dbCalls.
245249
*
246250
* @return array|object|null
251+
* @phpstan-return RowArray|object|null
247252
*/
248253
protected function doFirst()
249254
{
@@ -411,7 +416,7 @@ protected function doUpdateBatch(?array $set = null, ?string $index = null, int
411416
* @param array|int|string|null $id The rows primary key(s)
412417
* @param bool $purge Allows overriding the soft deletes setting.
413418
*
414-
* @return bool|string
419+
* @return bool|string SQL string when testMode
415420
*
416421
* @throws DatabaseException
417422
*/
@@ -450,7 +455,7 @@ protected function doDelete($id = null, bool $purge = false)
450455
* through soft deletes (deleted = 1)
451456
* This method works only with dbCalls.
452457
*
453-
* @return bool|string Returns a string if in test mode.
458+
* @return bool|string Returns a SQL string if in test mode.
454459
*/
455460
protected function doPurgeDeleted()
456461
{
@@ -491,7 +496,7 @@ protected function doReplace(?array $data = null, bool $returnSQL = false)
491496
* ['source' => 'message']
492497
* This method works only with dbCalls.
493498
*
494-
* @return array<string,string>
499+
* @return array<string, string>
495500
*/
496501
protected function doErrors()
497502
{

0 commit comments

Comments
 (0)