Skip to content

Commit

Permalink
Merge pull request #8187 from kenjis/docs-Model-phpdoc-types
Browse files Browse the repository at this point in the history
docs: add PHPDoc types to Model for PHPStan
  • Loading branch information
kenjis authored Nov 21, 2023
2 parents c844adb + 7675798 commit 8b9529f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
11 changes: 11 additions & 0 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
* - ensure validation is run against objects when saving items
* - process various callbacks
* - allow intermingling calls to the db connection
*
* @phpstan-type row_array array<int|string, float|int|null|string>
* @phpstan-type event_data_beforeinsert array{data: row_array}
* @phpstan-type event_data_afterinsert array{id: int|string, data: row_array, result: bool}
* @phpstan-type event_data_beforefind array{id?: int|string, method: string, singleton: bool, limit?: int, offset?: int}
* @phpstan-type event_data_afterfind array{id: int|string|null|list<int|string>, data: row_array|list<row_array>|object|null, method: string, singleton: bool}
* @phpstan-type event_data_beforeupdate array{id: null|list<int|string>, data: row_array}
* @phpstan-type event_data_afterupdate array{id: null|list<int|string>, data: row_array|object, result: bool}
* @phpstan-type event_data_beforedelete array{id: null|list<int|string>, purge: bool}
* @phpstan-type event_data_afterdelete array{id: null|list<int|string>, data: null, purge: bool, result: bool}
*/
abstract class BaseModel
{
Expand Down Expand Up @@ -539,6 +549,7 @@ abstract public function chunk(int $size, Closure $userFunc);
* @param array|int|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)
{
Expand Down
4 changes: 2 additions & 2 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2738,9 +2738,9 @@ public function getCompiledDelete(bool $reset = true): string
/**
* Compiles a delete string and runs the query
*
* @param mixed $where
* @param array|RawSql|string $where
*
* @return bool|string Returns a string if in test mode.
* @return bool|string Returns a SQL string if in test mode.
*
* @throws DatabaseException
*/
Expand Down
11 changes: 8 additions & 3 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
* @method $this where($key, $value = null, ?bool $escape = null)
* @method $this whereIn(?string $key = null, $values = null, ?bool $escape = null)
* @method $this whereNotIn(?string $key = null, $values = null, ?bool $escape = null)
*
* @phpstan-import-type row_array from BaseModel
*/
class Model extends BaseModel
{
Expand Down Expand Up @@ -178,6 +180,7 @@ public function setTable(string $table)
* @param array|int|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 ($singleton is true ? row_array|null|object : list<row_array|object>)
*/
protected function doFind(bool $singleton, $id = null)
{
Expand Down Expand Up @@ -224,6 +227,7 @@ protected function doFindColumn(string $columnName)
* @param int $offset Offset
*
* @return array
* @phpstan-return list<row_array|object>
*/
protected function doFindAll(int $limit = 0, int $offset = 0)
{
Expand All @@ -244,6 +248,7 @@ protected function doFindAll(int $limit = 0, int $offset = 0)
* This method works only with dbCalls.
*
* @return array|object|null
* @phpstan-return row_array|object|null
*/
protected function doFirst()
{
Expand Down Expand Up @@ -411,7 +416,7 @@ protected function doUpdateBatch(?array $set = null, ?string $index = null, int
* @param array|int|string|null $id The rows primary key(s)
* @param bool $purge Allows overriding the soft deletes setting.
*
* @return bool|string
* @return bool|string SQL string when testMode
*
* @throws DatabaseException
*/
Expand Down Expand Up @@ -450,7 +455,7 @@ protected function doDelete($id = null, bool $purge = false)
* through soft deletes (deleted = 1)
* This method works only with dbCalls.
*
* @return bool|string Returns a string if in test mode.
* @return bool|string Returns a SQL string if in test mode.
*/
protected function doPurgeDeleted()
{
Expand Down Expand Up @@ -491,7 +496,7 @@ protected function doReplace(?array $data = null, bool $returnSQL = false)
* ['source' => 'message']
* This method works only with dbCalls.
*
* @return array<string,string>
* @return array<string, string>
*/
protected function doErrors()
{
Expand Down

0 comments on commit 8b9529f

Please sign in to comment.