') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); refactor: use native phpdocs wherever possible by paulbalandan · Pull Request #9571 · codeigniter4/CodeIgniter4 · GitHub
Skip to content
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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