From e5acd55991affccc20bd61d91e6c8666bfc82999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amel=20Junuzovi=C4=87?= Date: Mon, 7 Oct 2024 01:00:02 +0200 Subject: [PATCH 1/2] protected bool $resetStmtId = true; --- phpstan-baseline.php | 6 ------ system/Database/OCI8/Connection.php | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 1ba751d7c11d..0adddadb5ec9 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -3085,12 +3085,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/OCI8/Connection.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.property - 'message' => '#^Property CodeIgniter\\\\Database\\\\OCI8\\\\Connection\\:\\:\\$resetStmtId has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/OCI8/Connection.php', -]; $ignoreErrors[] = [ // identifier: missingType.property 'message' => '#^Property CodeIgniter\\\\Database\\\\OCI8\\\\Connection\\:\\:\\$validDSNs has no type specified\\.$#', diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index 2b870b755b44..2dbc39a91661 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -79,7 +79,7 @@ class Connection extends BaseConnection * Used by storedProcedure() to prevent execute() from * re-setting the statement ID. */ - protected $resetStmtId = true; + protected bool $resetStmtId = true; /** * Statement ID From 9abad84d2717a7037c3a45f92565db02a0b4ca64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amel=20Junuzovi=C4=87?= Date: Mon, 7 Oct 2024 01:30:05 +0200 Subject: [PATCH 2/2] fix no return type --- phpstan-baseline.php | 54 ------------------------ system/Database/OCI8/Connection.php | 7 ++- system/Database/Postgre/Connection.php | 26 +++++++++--- system/Session/Handlers/ArrayHandler.php | 2 +- system/Test/Mock/MockCLIConfig.php | 21 +++++---- system/Test/Mock/MockCURLRequest.php | 6 +-- 6 files changed, 44 insertions(+), 72 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 0adddadb5ec9..9b25dfe58a2b 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -3085,12 +3085,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/OCI8/Connection.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.property - 'message' => '#^Property CodeIgniter\\\\Database\\\\OCI8\\\\Connection\\:\\:\\$validDSNs has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/OCI8/Connection.php', -]; $ignoreErrors[] = [ // identifier: method.childReturnType 'message' => '#^Return type \\(array\\{code\\: int\\|string\\|null, message\\: string\\|null\\}\\) of method CodeIgniter\\\\Database\\\\OCI8\\\\Connection\\:\\:error\\(\\) should be covariant with return type \\(array\\\\) of method CodeIgniter\\\\Database\\\\ConnectionInterface\\\\:\\:error\\(\\)$#', @@ -3319,30 +3313,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/Postgre/Connection.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.property - 'message' => '#^Property CodeIgniter\\\\Database\\\\Postgre\\\\Connection\\:\\:\\$connect_timeout has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/Postgre/Connection.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.property - 'message' => '#^Property CodeIgniter\\\\Database\\\\Postgre\\\\Connection\\:\\:\\$options has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/Postgre/Connection.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.property - 'message' => '#^Property CodeIgniter\\\\Database\\\\Postgre\\\\Connection\\:\\:\\$service has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/Postgre/Connection.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.property - 'message' => '#^Property CodeIgniter\\\\Database\\\\Postgre\\\\Connection\\:\\:\\$sslmode has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/Postgre/Connection.php', -]; $ignoreErrors[] = [ // identifier: method.childReturnType 'message' => '#^Return type \\(array\\\\) of method CodeIgniter\\\\Database\\\\Postgre\\\\Connection\\:\\:error\\(\\) should be covariant with return type \\(array\\{code\\: int\\|string\\|null, message\\: string\\|null\\}\\) of method CodeIgniter\\\\Database\\\\BaseConnection\\\\:\\:error\\(\\)$#', @@ -9457,12 +9427,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Test/Mock/MockBuilder.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.property - 'message' => '#^Property CodeIgniter\\\\Test\\\\Mock\\\\MockCLIConfig\\:\\:\\$CSRFExcludeURIs has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Test/Mock/MockCLIConfig.php', -]; $ignoreErrors[] = [ // identifier: missingType.return 'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockCURLRequest\\:\\:getBaseURI\\(\\) has no return type specified\\.$#', @@ -9487,24 +9451,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Test/Mock/MockCURLRequest.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.parameter - 'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockCURLRequest\\:\\:setOutput\\(\\) has parameter \\$output with no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Test/Mock/MockCURLRequest.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.property - 'message' => '#^Property CodeIgniter\\\\Test\\\\Mock\\\\MockCURLRequest\\:\\:\\$curl_options has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Test/Mock/MockCURLRequest.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.property - 'message' => '#^Property CodeIgniter\\\\Test\\\\Mock\\\\MockCURLRequest\\:\\:\\$output has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Test/Mock/MockCURLRequest.php', -]; $ignoreErrors[] = [ // identifier: missingType.iterableValue 'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockCache\\:\\:getMetaData\\(\\) return type has no value type specified in iterable type array\\.$#', diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index 2dbc39a91661..94c551bfeb03 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -52,7 +52,12 @@ class Connection extends BaseConnection 'rownum', ]; - protected $validDSNs = [ + /** + * Array of valid DSN patterns for different Oracle connections. + * + * @var array{tns: string,ec: string,in: string} + */ + protected array $validDSNs = [ // TNS 'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // Easy Connect string (Oracle 10g+). diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index ec886dbd4d8b..19e9aefc21c8 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -50,10 +50,22 @@ class Connection extends BaseConnection */ public $escapeChar = '"'; - protected $connect_timeout; - protected $options; - protected $sslmode; - protected $service; + /** + * @var int Connection timeout in seconds + */ + protected int $connect_timeout; + + /** + * @var string Connection options + */ + protected string $options; + + /** + * @var string Possible values are: disable, allow, prefer, require, verify-ca, verify-full + */ + protected string $sslmode; + + protected string $service; /** * Connect to the database. @@ -546,7 +558,11 @@ protected function buildDSN() // provided via string> Example: // // Postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1 - foreach (['connect_timeout', 'options', 'sslmode', 'service'] as $key) { + if (isset($this->connect_timeout)) { + $this->DSN .= "connect_timeout={$this->connect_timeout} "; + } + + foreach (['options', 'sslmode', 'service'] as $key) { if (isset($this->{$key}) && is_string($this->{$key}) && $this->{$key} !== '') { $this->DSN .= "{$key}='{$this->{$key}}' "; } diff --git a/system/Session/Handlers/ArrayHandler.php b/system/Session/Handlers/ArrayHandler.php index 8faa00fdc9d7..cb09d28aafe1 100644 --- a/system/Session/Handlers/ArrayHandler.php +++ b/system/Session/Handlers/ArrayHandler.php @@ -21,7 +21,7 @@ */ class ArrayHandler extends BaseHandler { - protected static $cache = []; + protected static array $cache = []; /** * Re-initialize existing session, or creates a new one. diff --git a/system/Test/Mock/MockCLIConfig.php b/system/Test/Mock/MockCLIConfig.php index c62df3d9f43a..99e3597d353a 100644 --- a/system/Test/Mock/MockCLIConfig.php +++ b/system/Test/Mock/MockCLIConfig.php @@ -17,14 +17,19 @@ class MockCLIConfig extends App { - public string $baseURL = 'http://example.com/'; - public string $uriProtocol = 'REQUEST_URI'; - public array $proxyIPs = []; - public string $CSRFTokenName = 'csrf_test_name'; - public string $CSRFCookieName = 'csrf_cookie_name'; - public int $CSRFExpire = 7200; - public bool $CSRFRegenerate = true; - public $CSRFExcludeURIs = ['http://example.com']; + public string $baseURL = 'http://example.com/'; + public string $uriProtocol = 'REQUEST_URI'; + public array $proxyIPs = []; + public string $CSRFTokenName = 'csrf_test_name'; + public string $CSRFCookieName = 'csrf_cookie_name'; + public int $CSRFExpire = 7200; + public bool $CSRFRegenerate = true; + + /** + * @var list + */ + public array $CSRFExcludeURIs = ['http://example.com']; + public string $CSRFSameSite = 'Lax'; public bool $CSPEnabled = false; public string $defaultLocale = 'en'; diff --git a/system/Test/Mock/MockCURLRequest.php b/system/Test/Mock/MockCURLRequest.php index 97f80e7c1da2..df9444f1e54e 100644 --- a/system/Test/Mock/MockCURLRequest.php +++ b/system/Test/Mock/MockCURLRequest.php @@ -24,10 +24,10 @@ */ class MockCURLRequest extends CURLRequest { - public $curl_options; - protected $output = ''; + public array $curl_options; + protected string $output = ''; - public function setOutput($output) + public function setOutput(string $output): static { $this->output = $output;