diff --git a/app/Config/Cookie.php b/app/Config/Cookie.php index 84ccc0e99d80..3bad184797ce 100644 --- a/app/Config/Cookie.php +++ b/app/Config/Cookie.php @@ -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'; diff --git a/psalm_autoload.php b/psalm_autoload.php index 5585212190dd..d8d92a892ce8 100644 --- a/psalm_autoload.php +++ b/psalm_autoload.php @@ -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', ]; diff --git a/system/API/ResponseTrait.php b/system/API/ResponseTrait.php index 5f2e068b3918..a2e93bfd309f 100644 --- a/system/API/ResponseTrait.php +++ b/system/API/ResponseTrait.php @@ -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'; @@ -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 */ diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 2e628f1590d6..86d922c33302 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -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>|list - * @phpstan-return ($prefix is null ? array> : list) + * @return ($prefix is null ? array> : list) */ public function getNamespace(?string $prefix = null) { diff --git a/system/BaseModel.php b/system/BaseModel.php index cf8df09998f3..a5762a23be7d 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -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 */ diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 2c89a5e2e4f1..560925d5f623 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -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; @@ -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 */ diff --git a/system/Commands/Translation/LocalizationFinder.php b/system/Commands/Translation/LocalizationFinder.php index 3307dab8a4e4..e6557b74d1c4 100644 --- a/system/Commands/Translation/LocalizationFinder.php +++ b/system/Commands/Translation/LocalizationFinder.php @@ -361,8 +361,7 @@ private function isSubDirectory(string $directory, string $rootDirectory): bool /** * @param list $files * - * @return array - * @phpstan-return array{'foundLanguageKeys': array>, 'badLanguageKeys': array>, 'countFiles': int} + * @return array{'foundLanguageKeys': array>, 'badLanguageKeys': array>, 'countFiles': int} */ private function findLanguageKeysInFiles(array $files): array { diff --git a/system/Common.php b/system/Common.php index 910ec9b1cc28..3f69838e0b80 100644 --- a/system/Common.php +++ b/system/Common.php @@ -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) { @@ -201,8 +200,7 @@ function command(string $command) * * @param class-string|string $name * - * @return ConfigTemplate|null - * @phpstan-return ($name is class-string ? ConfigTemplate : object|null) + * @return ($name is class-string ? ConfigTemplate : object|null) */ function config(string $name, bool $getShared = true) { @@ -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 * @@ -796,8 +794,7 @@ function log_message(string $level, string $message, array $context = []): void * * @param class-string|string $name * - * @return ModelTemplate|null - * @phpstan-return ($name is class-string ? ModelTemplate : object|null) + * @return ($name is class-string ? ModelTemplate : object|null) */ function model(string $name, bool $getShared = true, ?ConnectionInterface &$conn = null) { @@ -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 */ @@ -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) { @@ -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) { diff --git a/system/DataCaster/DataCaster.php b/system/DataCaster/DataCaster.php index ae3f40f4dc25..81ebe233c125 100644 --- a/system/DataCaster/DataCaster.php +++ b/system/DataCaster/DataCaster.php @@ -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 { diff --git a/system/DataConverter/DataConverter.php b/system/DataConverter/DataConverter.php index 43b42a08bbdf..fa8353e83abd 100644 --- a/system/DataConverter/DataConverter.php +++ b/system/DataConverter/DataConverter.php @@ -20,9 +20,9 @@ /** * PHP data <==> DataSource data converter * - * @see \CodeIgniter\DataConverter\DataConverterTest - * * @template TEntity of object + * + * @see \CodeIgniter\DataConverter\DataConverterTest */ final class DataConverter { @@ -52,14 +52,14 @@ public function __construct( * Static reconstruct method name or closure to reconstruct an object. * Used by reconstruct(). * - * @phpstan-var (Closure(array): TEntity)|string|null + * @var (Closure(array): 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|null + * @var (Closure(TEntity, bool, bool): array)|string|null */ private readonly Closure|string|null $extractor = null, ) { @@ -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 $classname - * @param array $row Raw data from database + * @param class-string $classname + * @param array $row Raw data from database * - * @phpstan-return TEntity + * @return TEntity * * @internal */ diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index b274b02aa5a8..1ae432dcb79c 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -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; @@ -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() { @@ -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) { @@ -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); @@ -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|bool|Query + * @return BaseResult|bool|Query * * @todo BC set $queryClass default as null in 4.1 */ @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -1787,8 +1777,7 @@ public function isWriteType($sql): bool * * Must return an array with keys 'code' and 'message': * - * @return array - * @phpstan-return array{code: int|string|null, message: string|null} + * @return array{code: int|string|null, message: string|null} */ abstract public function error(): array; diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index e9017bcf5ff9..3632ccb18c0c 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -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; @@ -61,8 +60,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface /** * A reference to the db connection to use. * - * @var BaseConnection - * @phpstan-var BaseConnection + * @var BaseConnection */ protected $db; @@ -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 + * @return bool|ResultInterface * * @throws DatabaseException */ diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index efbc16722148..fc2393edffee 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -27,16 +27,14 @@ abstract class BaseResult implements ResultInterface /** * Connection ID * - * @var object|resource - * @phpstan-var TConnection + * @var TConnection */ public $connID; /** * Result ID * - * @var false|object|resource - * @phpstan-var false|TResult + * @var false|TResult */ public $resultID; @@ -85,10 +83,8 @@ abstract class BaseResult implements ResultInterface /** * Constructor * - * @param object|resource $connID - * @param object|resource $resultID - * @phpstan-param TConnection $connID - * @phpstan-param TResult $resultID + * @param TConnection $connID + * @param TResult $resultID */ public function __construct(&$connID, &$resultID) { @@ -119,7 +115,7 @@ public function getResult(string $type = 'object'): array /** * Returns the results as an array of custom objects. * - * @phpstan-param class-string $className + * @param class-string $className * * @return array */ @@ -211,8 +207,7 @@ public function getResultArray(): array * * If no results, an empty array is returned. * - * @return array - * @phpstan-return list + * @return list */ public function getResultObject(): array { @@ -258,12 +253,10 @@ public function getResultObject(): array * * @template T of object * - * @param int|string $n The index of the results to return, or column name. - * @param string $type The type of result object. 'array', 'object' or class name. - * @phpstan-param class-string|'array'|'object' $type + * @param int|string $n The index of the results to return, or column name. + * @param 'array'|'object'|class-string $type The type of result object. 'array', 'object' or class name. * - * @return array|float|int|object|stdClass|string|null - * @phpstan-return ($n is string ? float|int|string|null : ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))) + * @return ($n is string ? float|int|string|null : ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))) */ public function getRow($n = 0, string $type = 'object') { @@ -300,11 +293,10 @@ public function getRow($n = 0, string $type = 'object') * * @template T of object * - * @param int $n The index of the results to return. - * @phpstan-param class-string $className + * @param int $n The index of the results to return. + * @param class-string $className * - * @return object|null - * @phpstan-return T|null + * @return T|null */ public function getCustomRowObject(int $n, string $className) { diff --git a/system/Database/ConnectionInterface.php b/system/Database/ConnectionInterface.php index 2f1c932c461d..8e4834486261 100644 --- a/system/Database/ConnectionInterface.php +++ b/system/Database/ConnectionInterface.php @@ -32,16 +32,14 @@ public function initialize(); /** * Connect to the database. * - * @return false|object|resource - * @phpstan-return false|TConnection + * @return false|TConnection */ public function connect(bool $persistent = false); /** * Create a persistent database connection. * - * @return false|object|resource - * @phpstan-return false|TConnection + * @return false|TConnection */ public function persistentConnect(); @@ -59,8 +57,7 @@ public function reconnect(); * 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 false|TConnection + * @return false|TConnection */ public function getConnection(?string $alias = null); @@ -105,8 +102,7 @@ public function getVersion(): string; * * @param array|string|null $binds * - * @return BaseResult|bool|Query - * @phpstan-return BaseResult|bool|Query + * @return BaseResult|bool|Query */ public function query(string $sql, $binds = null); @@ -115,8 +111,7 @@ public function query(string $sql, $binds = null); * 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); @@ -144,8 +139,7 @@ public function getLastQuery(); * * @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); diff --git a/system/Database/Forge.php b/system/Database/Forge.php index 8405d9f7143f..f6eb617fd389 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -846,8 +846,7 @@ public function modifyColumn(string $table, $fields): bool * @param array|string $processedFields Processed column definitions * or column names to DROP * - * @return false|list|string|null SQL string - * @phpstan-return ($alterType is 'DROP' ? string : list|false|null) + * @return ($alterType is 'DROP' ? string : false|list|null) */ protected function _alterTable(string $alterType, string $table, $processedFields) { diff --git a/system/Database/MySQLi/Forge.php b/system/Database/MySQLi/Forge.php index fe207f5267a5..9482f7e2329a 100644 --- a/system/Database/MySQLi/Forge.php +++ b/system/Database/MySQLi/Forge.php @@ -135,8 +135,7 @@ protected function _createTableAttributes(array $attributes): string * @param array|string $processedFields Processed column definitions * or column names to DROP * - * @return list|string SQL string - * @phpstan-return ($alterType is 'DROP' ? string : list) + * @return ($alterType is 'DROP' ? string : list) */ protected function _alterTable(string $alterType, string $table, $processedFields) { diff --git a/system/Database/OCI8/Forge.php b/system/Database/OCI8/Forge.php index f761045d9784..8f71169115ce 100644 --- a/system/Database/OCI8/Forge.php +++ b/system/Database/OCI8/Forge.php @@ -100,8 +100,7 @@ class Forge extends BaseForge * @param array|string $processedFields Processed column definitions * or column names to DROP * - * @return list|string SQL string - * @phpstan-return ($alterType is 'DROP' ? string : list) + * @return ($alterType is 'DROP' ? string : list) */ protected function _alterTable(string $alterType, string $table, $processedFields) { diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 584c452b233d..9b480975de2e 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -242,8 +242,7 @@ 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) { diff --git a/system/Database/Postgre/Forge.php b/system/Database/Postgre/Forge.php index b0a38c90ed23..8b18d7d48ca7 100644 --- a/system/Database/Postgre/Forge.php +++ b/system/Database/Postgre/Forge.php @@ -86,8 +86,7 @@ protected function _createTableAttributes(array $attributes): string * @param array|string $processedFields Processed column definitions * or column names to DROP * - * @return false|list|string SQL string or false - * @phpstan-return ($alterType is 'DROP' ? string : list|false) + * @return ($alterType is 'DROP' ? string : false|list) */ protected function _alterTable(string $alterType, string $table, $processedFields) { diff --git a/system/Database/PreparedQueryInterface.php b/system/Database/PreparedQueryInterface.php index 6ac69904e7f9..c49c2e7bb551 100644 --- a/system/Database/PreparedQueryInterface.php +++ b/system/Database/PreparedQueryInterface.php @@ -26,8 +26,7 @@ interface PreparedQueryInterface * 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 + * @return bool|ResultInterface */ public function execute(...$data); diff --git a/system/Database/ResultInterface.php b/system/Database/ResultInterface.php index e6383cab6585..89febfef835c 100644 --- a/system/Database/ResultInterface.php +++ b/system/Database/ResultInterface.php @@ -61,12 +61,10 @@ public function getResultObject(): array; * * @template T of object * - * @param int|string $n The index of the results to return, or column name. - * @param string $type The type of result object. 'array', 'object' or class name. - * @phpstan-param class-string|'array'|'object' $type + * @param int|string $n The index of the results to return, or column name. + * @param 'array'|'object'|class-string $type The type of result object. 'array', 'object' or class name. * - * @return array|float|int|object|stdClass|string|null - * @phpstan-return ($n is string ? float|int|string|null : ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))) + * @return ($n is string ? float|int|string|null : ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))) */ public function getRow($n = 0, string $type = 'object'); @@ -77,11 +75,10 @@ public function getRow($n = 0, string $type = 'object'); * * @template T of object * - * @param int $n The index of the results to return. - * @phpstan-param class-string $className + * @param int $n The index of the results to return. + * @param class-string $className * - * @return object|null - * @phpstan-return T|null + * @return T|null */ public function getCustomRowObject(int $n, string $className); diff --git a/system/Database/SQLSRV/Forge.php b/system/Database/SQLSRV/Forge.php index 7b1da6e85ba7..f35d8e7bbca2 100644 --- a/system/Database/SQLSRV/Forge.php +++ b/system/Database/SQLSRV/Forge.php @@ -180,8 +180,7 @@ protected function _createTableAttributes(array $attributes): string * @param array|string $processedFields Processed column definitions * or column names to DROP * - * @return false|list|string SQL string or false - * @phpstan-return ($alterType is 'DROP' ? string : list|false) + * @return ($alterType is 'DROP' ? string : false|list) */ protected function _alterTable(string $alterType, string $table, $processedFields) { diff --git a/system/Database/SQLite3/Forge.php b/system/Database/SQLite3/Forge.php index 31c2a7ed58a6..2bb9386f6c9e 100644 --- a/system/Database/SQLite3/Forge.php +++ b/system/Database/SQLite3/Forge.php @@ -139,9 +139,7 @@ public function dropColumn(string $table, $columnNames): bool * @param array|string $processedFields Processed column definitions * or column names to DROP * - * @return array|string|null - * @return list|string|null SQL string or null - * @phpstan-return ($alterType is 'DROP' ? string : list|null) + * @return ($alterType is 'DROP' ? string : list|null) */ protected function _alterTable(string $alterType, string $table, $processedFields) { diff --git a/system/Database/SQLite3/Table.php b/system/Database/SQLite3/Table.php index 674d26b7d6f2..ea84e0011e3f 100644 --- a/system/Database/SQLite3/Table.php +++ b/system/Database/SQLite3/Table.php @@ -376,8 +376,7 @@ protected function copyData() * * @param array|bool $fields * - * @return mixed - * @phpstan-return ($fields is array ? array : mixed) + * @return ($fields is array ? array : mixed) */ protected function formatFields($fields) { diff --git a/system/Files/File.php b/system/Files/File.php index 23eb324d2684..be7f84f8a20b 100644 --- a/system/Files/File.php +++ b/system/Files/File.php @@ -73,7 +73,7 @@ public function getSize() /** * Retrieve the file size by unit, calculated in IEC standards with 1024 as base value. * - * @phpstan-param positive-int $precision + * @param positive-int $precision */ public function getSizeByBinaryUnit(FileSizeUnit $unit = FileSizeUnit::B, int $precision = 3): int|string { @@ -83,7 +83,7 @@ public function getSizeByBinaryUnit(FileSizeUnit $unit = FileSizeUnit::B, int $p /** * Retrieve the file size by unit, calculated in metric standards with 1000 as base value. * - * @phpstan-param positive-int $precision + * @param positive-int $precision */ public function getSizeByMetricUnit(FileSizeUnit $unit = FileSizeUnit::B, int $precision = 3): int|string { diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index 412a9f457d53..9a253a42b359 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -206,8 +206,8 @@ public function setResponse(ResponseInterface $response) * Runs through all the filters (except "Required Filters") for the specified * URI and position. * - * @param string $uri URI path relative to baseURL - * @phpstan-param 'before'|'after' $position + * @param string $uri URI path relative to baseURL + * @param 'after'|'before' $position * * @return RequestInterface|ResponseInterface|string|null * @@ -310,7 +310,7 @@ private function createFilter(string $className): FilterInterface /** * Returns the "Required Filters" class list. * - * @phpstan-param 'before'|'after' $position + * @param 'after'|'before' $position * * @return list}> [[classname, arguments], ...] */ @@ -340,7 +340,7 @@ public function getRequiredClasses(string $position): array /** * Runs "Required Filters" for the specified position. * - * @phpstan-param 'before'|'after' $position + * @param 'after'|'before' $position * * @return RequestInterface|ResponseInterface|string|null * @@ -367,7 +367,7 @@ public function runRequired(string $position = 'before') /** * Returns "Required Filters" for the specified position. * - * @phpstan-param 'before'|'after' $position + * @param 'after'|'before' $position * * @internal */ @@ -544,7 +544,7 @@ public function getFiltersClass(): array * MUST be called prior to initialize(); * Intended for use within routes files. * - * @phpstan-param 'before'|'after' $position + * @param 'after'|'before' $position * * @return $this */ @@ -574,9 +574,9 @@ public function addFilter(string $class, ?string $alias = null, string $position * after the filter name, followed by a comma-separated list of arguments that * are passed to the filter when executed. * - * @param string $filter filter_name or filter_name:arguments like 'role:admin,manager' - * or filter classname. - * @phpstan-param 'before'|'after' $position + * @param string $filter filter_name or filter_name:arguments like 'role:admin,manager' + * or filter classname. + * @param 'after'|'before' $position */ private function enableFilter(string $filter, string $position = 'before'): void { @@ -824,7 +824,7 @@ protected function processFilters(?string $uri = null) /** * Maps filter aliases to the equivalent filter classes * - * @phpstan-param 'before'|'after' $position + * @param 'after'|'before' $position * * @return void * diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php index 6ef97170914e..bde4e1b8e3f8 100644 --- a/system/HTTP/CLIRequest.php +++ b/system/HTTP/CLIRequest.php @@ -314,9 +314,6 @@ public function getLocale(): string /** * Checks this request type. - * - * @param string $type HTTP verb or 'json' or 'ajax' - * @phpstan-param string|'get'|'post'|'put'|'delete'|'head'|'patch'|'options'|'json'|'ajax' $type */ public function is(string $type): bool { diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php index ba6f61d7349f..72b1ce0ca5df 100644 --- a/system/HTTP/IncomingRequest.php +++ b/system/HTTP/IncomingRequest.php @@ -348,9 +348,6 @@ public function negotiate(string $type, array $supported, bool $strictMatch = fa /** * Checks this request type. - * - * @param string $type HTTP verb or 'json' or 'ajax' - * @phpstan-param string|'get'|'post'|'put'|'delete'|'head'|'patch'|'options'|'json'|'ajax' $type */ public function is(string $type): bool { diff --git a/system/HTTP/RequestTrait.php b/system/HTTP/RequestTrait.php index 39f4269ef1df..3c3da161a3be 100644 --- a/system/HTTP/RequestTrait.php +++ b/system/HTTP/RequestTrait.php @@ -224,9 +224,8 @@ public function getEnv($index = null, $filter = null, $flags = null) /** * Allows manually setting the value of PHP global, like $_GET, $_POST, etc. * - * @param string $name Supergrlobal name (lowercase) - * @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name - * @param mixed $value + * @param 'cookie'|'get'|'post'|'request'|'server' $name Superglobal name (lowercase) + * @param mixed $value * * @return $this */ @@ -247,11 +246,10 @@ public function setGlobal(string $name, $value) * * http://php.net/manual/en/filter.filters.sanitize.php * - * @param string $name Supergrlobal name (lowercase) - * @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name - * @param array|int|string|null $index - * @param int|null $filter Filter constant - * @param array|int|null $flags Options + * @param 'cookie'|'get'|'post'|'request'|'server' $name Superglobal name (lowercase) + * @param array|int|string|null $index + * @param int|null $filter Filter constant + * @param array|int|null $flags Options * * @return array|bool|float|int|object|string|null */ @@ -341,8 +339,7 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f * Saves a copy of the current state of one of several PHP globals, * so we can retrieve them later. * - * @param string $name Superglobal name (lowercase) - * @phpstan-param 'get'|'post'|'request'|'cookie'|'server' $name + * @param 'cookie'|'get'|'post'|'request'|'server' $name Superglobal name (lowercase) * * @return void */ diff --git a/system/HTTP/SiteURI.php b/system/HTTP/SiteURI.php index 6e5206a0d493..d6653b10f537 100644 --- a/system/HTTP/SiteURI.php +++ b/system/HTTP/SiteURI.php @@ -85,11 +85,10 @@ class SiteURI extends URI private string $routePath; /** - * @param string $relativePath URI path relative to baseURL. May include - * queries or fragments. - * @param string|null $host Optional current hostname. - * @param string|null $scheme Optional scheme. 'http' or 'https'. - * @phpstan-param 'http'|'https'|null $scheme + * @param string $relativePath URI path relative to baseURL. May include + * queries or fragments. + * @param string|null $host Optional current hostname. + * @param 'http'|'https'|null $scheme Optional scheme. 'http' or 'https'. */ public function __construct( App $configApp, diff --git a/system/Model.php b/system/Model.php index 473584cb8163..802dd84dcdca 100644 --- a/system/Model.php +++ b/system/Model.php @@ -778,8 +778,7 @@ protected function shouldUpdate($row): bool * @phpstan-param row_array|object|null $row * @param bool $returnID Whether insert ID should be returned or not. * - * @return bool|int|string - * @phpstan-return ($returnID is true ? int|string|false : bool) + * @return ($returnID is true ? false|int|string : bool) * * @throws ReflectionException */ diff --git a/system/RESTful/ResourceController.php b/system/RESTful/ResourceController.php index 072b52ee8260..ed72df212b07 100644 --- a/system/RESTful/ResourceController.php +++ b/system/RESTful/ResourceController.php @@ -106,8 +106,7 @@ public function delete($id = null) /** * Set/change the expected response representation for returned objects * - * @param string $format Response format - * @phpstan-param 'json'|'xml' $format + * @param 'json'|'xml' $format Response format * * @return void */ diff --git a/system/Test/Mock/MockInputOutput.php b/system/Test/Mock/MockInputOutput.php index 7f4370a2d22f..0333bf27ccdf 100644 --- a/system/Test/Mock/MockInputOutput.php +++ b/system/Test/Mock/MockInputOutput.php @@ -31,16 +31,14 @@ final class MockInputOutput extends InputOutput /** * Output lines. * - * @var array - * @phpstan-var list + * @var list */ private array $outputs = []; /** * Sets user inputs. * - * @param array $inputs - * @phpstan-param list $inputs + * @param list $inputs */ public function setInputs(array $inputs): void { diff --git a/system/Traits/ConditionalTrait.php b/system/Traits/ConditionalTrait.php index a778e9375a36..027890309ba9 100644 --- a/system/Traits/ConditionalTrait.php +++ b/system/Traits/ConditionalTrait.php @@ -20,10 +20,10 @@ trait ConditionalTrait * * @template TWhen of mixed * - * @phpstan-param TWhen $condition - * @phpstan-param callable(self, TWhen): mixed $callback - * @phpstan-param (callable(self): mixed)|null $defaultCallback - * @param array|bool|float|int|object|resource|string|null $condition + * @param TWhen $condition + * @param callable(self, TWhen): mixed $callback + * @param (callable(self): mixed)|null $defaultCallback + * @param mixed $condition * * @return $this */ @@ -43,10 +43,10 @@ public function when($condition, callable $callback, ?callable $defaultCallback * * @template TWhenNot of mixed * - * @phpstan-param TWhenNot $condition - * @phpstan-param callable(self, TWhenNot): mixed $callback - * @phpstan-param (callable(self): mixed)|null $defaultCallback - * @param array|bool|float|int|object|resource|string|null $condition + * @param TWhenNot $condition + * @param callable(self, TWhenNot): mixed $callback + * @param (callable(self): mixed)|null $defaultCallback + * @param mixed $condition * * @return $this */ diff --git a/system/View/Cell.php b/system/View/Cell.php index f2801e4194ec..79e573f5103e 100644 --- a/system/View/Cell.php +++ b/system/View/Cell.php @@ -116,8 +116,7 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c * If a string, it should be in the format "key1=value key2=value". * It will be split and returned as an array. * - * @param array|string|null $params - * @phpstan-param array|string|float|null $params + * @param array|float|string|null $params * * @return array */ diff --git a/system/View/Filters.php b/system/View/Filters.php index 0be48b6de1b4..c74e385cdb96 100644 --- a/system/View/Filters.php +++ b/system/View/Filters.php @@ -77,8 +77,8 @@ public static function default($value, string $default): string /** * Escapes the given value with our `esc()` helper function. * - * @param string $value - * @phpstan-param 'html'|'js'|'css'|'url'|'attr'|'raw' $context + * @param string $value + * @param 'attr'|'css'|'html'|'js'|'raw'|'url' $context */ public static function esc($value, string $context = 'html'): string { diff --git a/system/View/Parser.php b/system/View/Parser.php index a2393bb4b7e5..e2a093904cc7 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -198,10 +198,9 @@ public function renderString(string $template, ?array $options = null, ?bool $sa * so that the variable is correctly handled within the * parsing itself, and contexts (including raw) are respected. * - * @param array $data - * @param non-empty-string|null $context The context to escape it for. - * If 'raw', no escaping will happen. - * @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context + * @param array $data + * @param 'attr'|'css'|'html'|'js'|'raw'|'url'|null $context The context to escape it for. + * If 'raw', no escaping will happen. */ public function setData(array $data = [], ?string $context = null): RendererInterface { diff --git a/system/View/RendererInterface.php b/system/View/RendererInterface.php index 5fdf8794f12d..d42dcee88442 100644 --- a/system/View/RendererInterface.php +++ b/system/View/RendererInterface.php @@ -46,10 +46,9 @@ public function renderString(string $view, ?array $options = null, bool $saveDat /** * Sets several pieces of view data at once. * - * @param array $data - * @param non-empty-string|null $context The context to escape it for. - * If 'raw', no escaping will happen. - * @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context + * @param array $data + * @param 'attr'|'css'|'html'|'js'|'raw'|'url'|null $context The context to escape it for. + * If 'raw', no escaping will happen. * * @return RendererInterface */ @@ -58,10 +57,9 @@ public function setData(array $data = [], ?string $context = null); /** * Sets a single piece of view data. * - * @param mixed $value - * @param non-empty-string|null $context The context to escape it for. - * If 'raw', no escaping will happen. - * @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context + * @param mixed $value + * @param 'attr'|'css'|'html'|'js'|'raw'|'url'|null $context The context to escape it for. + * If 'raw', no escaping will happen. * * @return RendererInterface */ diff --git a/system/View/Table.php b/system/View/Table.php index a063e71c5a85..df4b870b8ba9 100644 --- a/system/View/Table.php +++ b/system/View/Table.php @@ -108,8 +108,7 @@ public function __construct($config = []) /** * Set the template * - * @param array $template - * @phpstan-param array|string $template + * @param array|string $template * * @return bool */ diff --git a/system/View/View.php b/system/View/View.php index 6a282096ccb4..0f10b55ef5ab 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -335,9 +335,8 @@ public function excerpt(string $string, int $length = 20): string /** * Sets several pieces of view data at once. * - * @param non-empty-string|null $context The context to escape it for. - * If 'raw', no escaping will happen. - * @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context + * @param 'attr'|'css'|'html'|'js'|'raw'|'url'|null $context The context to escape it for. + * If 'raw', no escaping will happen. */ public function setData(array $data = [], ?string $context = null): RendererInterface { @@ -354,10 +353,9 @@ public function setData(array $data = [], ?string $context = null): RendererInte /** * Sets a single piece of view data. * - * @param mixed $value - * @param non-empty-string|null $context The context to escape it for. - * If 'raw', no escaping will happen. - * @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context + * @param mixed $value + * @param 'attr'|'css'|'html'|'js'|'raw'|'url'|null $context The context to escape it for. + * If 'raw', no escaping will happen. */ public function setVar(string $name, $value = null, ?string $context = null): RendererInterface { diff --git a/utils/phpstan-baseline/booleanAnd.rightNotBoolean.neon b/utils/phpstan-baseline/booleanAnd.rightNotBoolean.neon new file mode 100644 index 000000000000..44f6a2a063b0 --- /dev/null +++ b/utils/phpstan-baseline/booleanAnd.rightNotBoolean.neon @@ -0,0 +1,8 @@ +# total 1 error + +parameters: + ignoreErrors: + - + message: '#^Only booleans are allowed in &&, mixed given on the right side\.$#' + count: 1 + path: ../../system/View/Parser.php diff --git a/utils/phpstan-baseline/if.condNotBoolean.neon b/utils/phpstan-baseline/if.condNotBoolean.neon new file mode 100644 index 000000000000..e11e57b224cc --- /dev/null +++ b/utils/phpstan-baseline/if.condNotBoolean.neon @@ -0,0 +1,8 @@ +# total 1 error + +parameters: + ignoreErrors: + - + message: '#^Only booleans are allowed in an if condition, mixed given\.$#' + count: 1 + path: ../../system/View/View.php diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index e54589fea853..0f432eeac1e8 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -2,6 +2,7 @@ includes: - argument.type.neon - assign.propertyType.neon + - booleanAnd.rightNotBoolean.neon - codeigniter.cacheHandlerInstance.neon - codeigniter.getReassignArray.neon - codeigniter.modelArgumentType.neon @@ -9,6 +10,7 @@ includes: - codeigniter.superglobalAccessAssign.neon - deadCode.unreachable.neon - empty.notAllowed.neon + - if.condNotBoolean.neon - method.alreadyNarrowedType.neon - method.childParameterType.neon - method.childReturnType.neon diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index 8ecc1166e8bd..e972a65176a2 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,4 +1,4 @@ -# total 1576 errors +# total 1574 errors parameters: ignoreErrors: @@ -532,11 +532,6 @@ parameters: count: 1 path: ../../system/Commands/Utilities/Routes/FilterFinder.php - - - message: '#^Function cache\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Common.php - - message: '#^Function class_uses_recursive\(\) return type has no value type specified in iterable type array\.$#' count: 1 @@ -587,11 +582,6 @@ parameters: count: 1 path: ../../system/Common.php - - - message: '#^Function session\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Common.php - - message: '#^Function single_service\(\) has parameter \$params with no value type specified in iterable type array\.$#' count: 1