Skip to content

refactor: use native phpdocs wherever possible #9571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Config/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Cookie extends BaseConfig
* (empty string) means default SameSite attribute set by browsers (`Lax`)
* will be set on cookies. If set to `None`, `$secure` must also be set.
*
* @phpstan-var 'None'|'Lax'|'Strict'|''
* @var ''|'Lax'|'None'|'Strict'
*/
public string $samesite = 'Lax';

Expand Down
7 changes: 6 additions & 1 deletion psalm_autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@
}

$dirs = [
'tests/_support/Controllers',
'tests/_support/_controller',
'tests/_support/Controllers',
'tests/_support/Entity',
'tests/_support/Entity/Cast',
'tests/_support/Models',
'tests/_support/Validation',
'tests/_support/View',
'tests/system/Config/fixtures',
];

Expand Down
6 changes: 2 additions & 4 deletions system/API/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ trait ResponseTrait
* Either 'json' or 'xml'. If null is set, it will be determined through
* content negotiation.
*
* @var string|null
* @phpstan-var 'html'|'json'|'xml'|null
* @var 'html'|'json'|'xml'|null
*/
protected $format = 'json';

Expand Down Expand Up @@ -348,8 +347,7 @@ protected function format($data = null)
/**
* Sets the format the response should be in.
*
* @param string|null $format Response format
* @phpstan-param 'json'|'xml' $format
* @param 'json'|'xml' $format Response format
*
* @return $this
*/
Expand Down
3 changes: 1 addition & 2 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ public function addNamespace($namespace, ?string $path = null)
*
* If a prefix param is set, returns only paths to the given prefix.
*
* @return array<string, list<string>>|list<string>
* @phpstan-return ($prefix is null ? array<string, list<string>> : list<string>)
* @return ($prefix is null ? array<string, list<string>> : list<string>)
*/
public function getNamespace(?string $prefix = null)
{
Expand Down
3 changes: 1 addition & 2 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,7 @@ public function getInsertID()
* @phpstan-param row_array|object|null $row
* @param bool $returnID Whether insert ID should be returned or not.
*
* @return bool|int|string insert ID or true on success. false on failure.
* @phpstan-return ($returnID is true ? int|string|false : bool)
* @return ($returnID is true ? false|int|string : bool)
*
* @throws ReflectionException
*/
Expand Down
4 changes: 2 additions & 2 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class CodeIgniter
* web: Invoked by HTTP request
* php-cli: Invoked by CLI via `php public/index.php`
*
* @phpstan-var 'php-cli'|'web'
* @var 'php-cli'|'web'|null
*/
protected ?string $context = null;

Expand Down Expand Up @@ -1128,7 +1128,7 @@ protected function callExit($code)
/**
* Sets the app context.
*
* @phpstan-param 'php-cli'|'web' $context
* @param 'php-cli'|'web' $context
*
* @return $this
*/
Expand Down
3 changes: 1 addition & 2 deletions system/Commands/Translation/LocalizationFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,7 @@ private function isSubDirectory(string $directory, string $rootDirectory): bool
/**
* @param list<SplFileInfo> $files
*
* @return array<string, array|int>
* @phpstan-return array{'foundLanguageKeys': array<string, array<string, string>>, 'badLanguageKeys': array<int, array<int, string>>, 'countFiles': int}
* @return array{'foundLanguageKeys': array<string, array<string, string>>, 'badLanguageKeys': array<int, array<int, string>>, 'countFiles': int}
*/
private function findLanguageKeysInFiles(array $files): array
{
Expand Down
30 changes: 12 additions & 18 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ function app_timezone(): string
* cache()->save('foo', 'bar');
* $foo = cache('bar');
*
* @return array|bool|CacheInterface|float|int|object|string|null
* @phpstan-return ($key is null ? CacheInterface : array|bool|float|int|object|string|null)
* @return ($key is null ? CacheInterface : mixed)
*/
function cache(?string $key = null)
{
Expand Down Expand Up @@ -201,8 +200,7 @@ function command(string $command)
*
* @param class-string<ConfigTemplate>|string $name
*
* @return ConfigTemplate|null
* @phpstan-return ($name is class-string<ConfigTemplate> ? ConfigTemplate : object|null)
* @return ($name is class-string<ConfigTemplate> ? ConfigTemplate : object|null)
*/
function config(string $name, bool $getShared = true)
{
Expand Down Expand Up @@ -404,11 +402,11 @@ function env(string $key, $default = null)
* If $data is an array, then it loops over it, escaping each
* 'value' of the key/value pairs.
*
* @param array|string $data
* @phpstan-param 'html'|'js'|'css'|'url'|'attr'|'raw' $context
* @param string|null $encoding Current encoding for escaping.
* If not UTF-8, we convert strings from this encoding
* pre-escaping and back to this encoding post-escaping.
* @param array|string $data
* @param 'attr'|'css'|'html'|'js'|'raw'|'url' $context
* @param string|null $encoding Current encoding for escaping.
* If not UTF-8, we convert strings from this encoding
* pre-escaping and back to this encoding post-escaping.
*
* @return array|string
*
Expand Down Expand Up @@ -796,8 +794,7 @@ function log_message(string $level, string $message, array $context = []): void
*
* @param class-string<ModelTemplate>|string $name
*
* @return ModelTemplate|null
* @phpstan-return ($name is class-string<ModelTemplate> ? ModelTemplate : object|null)
* @return ($name is class-string<ModelTemplate> ? ModelTemplate : object|null)
*/
function model(string $name, bool $getShared = true, ?ConnectionInterface &$conn = null)
{
Expand All @@ -810,9 +807,8 @@ function model(string $name, bool $getShared = true, ?ConnectionInterface &$conn
* Provides access to "old input" that was set in the session
* during a redirect()->withInput().
*
* @param string|null $default
* @param false|string $escape
* @phpstan-param false|'attr'|'css'|'html'|'js'|'raw'|'url' $escape
* @param string|null $default
* @param 'attr'|'css'|'html'|'js'|'raw'|'url'|false $escape
*
* @return array|string|null
*/
Expand Down Expand Up @@ -965,8 +961,7 @@ function route_to(string $method, ...$params)
* session()->set('foo', 'bar');
* $foo = session('bar');
*
* @return array|bool|float|int|object|Session|string|null
* @phpstan-return ($val is null ? Session : array|bool|float|int|object|string|null)
* @return ($val is null ? Session : mixed)
*/
function session(?string $val = null)
{
Expand Down Expand Up @@ -1123,8 +1118,7 @@ function stringify_attributes($attributes, bool $js = false): string
* @param non-empty-string|null $name
* @param (callable(): mixed)|null $callable
*
* @return mixed|Timer
* @phpstan-return ($name is null ? Timer : ($callable is (callable(): mixed) ? mixed : Timer))
* @return ($name is null ? Timer : ($callable is (callable(): mixed) ? mixed : Timer))
*/
function timer(?string $name = null, ?callable $callable = null)
{
Expand Down
7 changes: 3 additions & 4 deletions system/DataCaster/DataCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ public function setTypes(array $types): static
* Add ? at the beginning of the type (i.e. ?string) to get `null`
* instead of casting $value when $value is null.
*
* @param mixed $value The value to convert
* @param string $field The field name
* @param string $method Allowed to "get" and "set"
* @phpstan-param 'get'|'set' $method
* @param mixed $value The value to convert
* @param string $field The field name
* @param 'get'|'set' $method Allowed to "get" and "set"
*/
public function castAs(mixed $value, string $field, string $method = 'get'): mixed
{
Expand Down
15 changes: 7 additions & 8 deletions system/DataConverter/DataConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
/**
* PHP data <==> DataSource data converter
*
* @see \CodeIgniter\DataConverter\DataConverterTest
*
* @template TEntity of object
*
* @see \CodeIgniter\DataConverter\DataConverterTest
*/
final class DataConverter
{
Expand Down Expand Up @@ -52,14 +52,14 @@ public function __construct(
* Static reconstruct method name or closure to reconstruct an object.
* Used by reconstruct().
*
* @phpstan-var (Closure(array<string, mixed>): TEntity)|string|null
* @var (Closure(array<string, mixed>): TEntity)|string|null
*/
private readonly Closure|string|null $reconstructor = 'reconstruct',
/**
* Extract method name or closure to extract data from an object.
* Used by extract().
*
* @phpstan-var (Closure(TEntity, bool, bool): array<string, mixed>)|string|null
* @var (Closure(TEntity, bool, bool): array<string, mixed>)|string|null
*/
private readonly Closure|string|null $extractor = null,
) {
Expand Down Expand Up @@ -105,11 +105,10 @@ public function toDataSource(array $phpData): array
/**
* Takes database data array and creates a specified type object.
*
* @param class-string $classname
* @phpstan-param class-string<TEntity> $classname
* @param array<string, mixed> $row Raw data from database
* @param class-string<TEntity> $classname
* @param array<string, mixed> $row Raw data from database
*
* @phpstan-return TEntity
* @return TEntity
*
* @internal
*/
Expand Down
33 changes: 11 additions & 22 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,14 @@ abstract class BaseConnection implements ConnectionInterface
/**
* Connection ID
*
* @var false|object|resource
* @phpstan-var false|TConnection
* @var false|TConnection
*/
public $connID = false;

/**
* Result ID
*
* @var false|object|resource
* @phpstan-var false|TResult
* @var false|TResult
*/
public $resultID = false;

Expand Down Expand Up @@ -498,8 +496,7 @@ abstract protected function _close();
/**
* Create a persistent database connection.
*
* @return false|object|resource
* @phpstan-return false|TConnection
* @return false|TConnection
*/
public function persistentConnect()
{
Expand All @@ -512,8 +509,7 @@ public function persistentConnect()
* get that connection. If you pass either alias in and only a single
* connection is present, it must return the sole connection.
*
* @return false|object|resource
* @phpstan-return TConnection
* @return false|TConnection
*/
public function getConnection(?string $alias = null)
{
Expand Down Expand Up @@ -592,8 +588,7 @@ public function addTableAlias(string $alias)
/**
* Executes the query against the database.
*
* @return false|object|resource
* @phpstan-return false|TResult
* @return false|TResult
*/
abstract protected function execute(string $sql);

Expand All @@ -607,8 +602,7 @@ abstract protected function execute(string $sql);
*
* @param array|string|null $binds
*
* @return BaseResult|bool|Query BaseResult when “read” type query, bool when “write” type query, Query when prepared query
* @phpstan-return BaseResult<TConnection, TResult>|bool|Query
* @return BaseResult<TConnection, TResult>|bool|Query
*
* @todo BC set $queryClass default as null in 4.1
*/
Expand Down Expand Up @@ -726,8 +720,7 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s
* is performed, nor are transactions handled. Simply takes a raw
* query string and returns the database-specific result id.
*
* @return false|object|resource
* @phpstan-return false|TResult
* @return false|TResult
*/
public function simpleQuery(string $sql)
{
Expand Down Expand Up @@ -1065,8 +1058,7 @@ public function getConnectDuration(int $decimals = 6): string
* @param bool $protectIdentifiers Protect table or column names?
* @param bool $fieldExists Supplied $item contains a column name?
*
* @return array|string
* @phpstan-return ($item is array ? array : string)
* @return ($item is array ? array : string)
*/
public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $protectIdentifiers = null, bool $fieldExists = true)
{
Expand Down Expand Up @@ -1270,8 +1262,7 @@ private function escapeTableName(TableName $tableName): string
*
* @param array|string $item
*
* @return array|string
* @phpstan-return ($item is array ? array : string)
* @return ($item is array ? array : string)
*/
public function escapeIdentifiers($item)
{
Expand Down Expand Up @@ -1355,8 +1346,7 @@ abstract public function affectedRows(): int;
*
* @param array|bool|float|int|object|string|null $str
*
* @return array|float|int|string
* @phpstan-return ($str is array ? array : float|int|string)
* @return ($str is array ? array : float|int|string)
*/
public function escape($str)
{
Expand Down Expand Up @@ -1787,8 +1777,7 @@ public function isWriteType($sql): bool
*
* Must return an array with keys 'code' and 'message':
*
* @return array<string, int|string|null>
* @phpstan-return array{code: int|string|null, message: string|null}
* @return array{code: int|string|null, message: string|null}
*/
abstract public function error(): array;

Expand Down
9 changes: 3 additions & 6 deletions system/Database/BasePreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface
/**
* The prepared statement itself.
*
* @var object|resource|null
* @phpstan-var TStatement|null
* @var TStatement|null
*/
protected $statement;

Expand Down Expand Up @@ -61,8 +60,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface
/**
* A reference to the db connection to use.
*
* @var BaseConnection
* @phpstan-var BaseConnection<TConnection, TResult>
* @var BaseConnection<TConnection, TResult>
*/
protected $db;

Expand Down Expand Up @@ -112,8 +110,7 @@ abstract public function _prepare(string $sql, array $options = []);
* Takes a new set of data and runs it against the currently
* prepared query. Upon success, will return a Results object.
*
* @return bool|ResultInterface
* @phpstan-return bool|ResultInterface<TConnection, TResult>
* @return bool|ResultInterface<TConnection, TResult>
*
* @throws DatabaseException
*/
Expand Down
Loading
Loading