From b897039c890b524bf4f5c57b66ae182909b7d180 Mon Sep 17 00:00:00 2001 From: chingyi lan Date: Fri, 4 Aug 2023 11:25:37 +0800 Subject: [PATCH 1/5] dev: phpstan helpers --- phpstan-baseline.php | 40 -------------------------------- system/Helpers/cookie_helper.php | 4 ++++ system/Helpers/kint_helper.php | 28 +++++++++++++++++++++- system/Helpers/test_helper.php | 2 ++ 4 files changed, 33 insertions(+), 41 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index a7fd4cba69c0..9ed028147f1d 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1246,51 +1246,11 @@ 'count' => 1, 'path' => __DIR__ . '/system/HTTP/UserAgent.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Function delete_cookie\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Helpers/cookie_helper.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Function set_cookie\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Helpers/cookie_helper.php', -]; $ignoreErrors[] = [ 'message' => '#^Right side of && is always true\\.$#', 'count' => 1, 'path' => __DIR__ . '/system/Helpers/filesystem_helper.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Function d\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Helpers/kint_helper.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Function d\\(\\) has parameter \\$vars with no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Helpers/kint_helper.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Function dd\\(\\) has no return type specified\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/Helpers/kint_helper.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Function dd\\(\\) has parameter \\$vars with no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Helpers/kint_helper.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Function trace\\(\\) has no return type specified\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/Helpers/kint_helper.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Function mock\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Helpers/test_helper.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Honeypot\\\\Exceptions\\\\HoneypotException\\:\\:forNoHiddenValue\\(\\) has no return type specified\\.$#', 'count' => 1, diff --git a/system/Helpers/cookie_helper.php b/system/Helpers/cookie_helper.php index 9fc004c28b9a..379481b45376 100755 --- a/system/Helpers/cookie_helper.php +++ b/system/Helpers/cookie_helper.php @@ -34,6 +34,8 @@ * @param bool|null $httpOnly True makes the cookie accessible via http(s) only (no javascript) * @param string|null $sameSite The cookie SameSite value * + * @return void + * * @see \CodeIgniter\HTTP\Response::setCookie() */ function set_cookie( @@ -91,6 +93,8 @@ function get_cookie($index, bool $xssClean = false, ?string $prefix = '') * @param string $path the cookie path * @param string $prefix the cookie prefix * + * @return void + * * @see \CodeIgniter\HTTP\Response::deleteCookie() */ function delete_cookie($name, string $domain = '', string $path = '/', string $prefix = '') diff --git a/system/Helpers/kint_helper.php b/system/Helpers/kint_helper.php index 10c4f34e938d..1688c1746c2d 100644 --- a/system/Helpers/kint_helper.php +++ b/system/Helpers/kint_helper.php @@ -16,7 +16,9 @@ /** * Prints a Kint debug report and exits. * - * @param array ...$vars + * @param array $vars + * + * @return void * * @codeCoverageIgnore Can't be tested ... exits */ @@ -31,6 +33,13 @@ function dd(...$vars) } } else { // In case that Kint is not loaded. + /** + * dd function + * + * @param array $vars + * + * @return int + */ function dd(...$vars) { return 0; @@ -40,6 +49,13 @@ function dd(...$vars) if (! function_exists('d') && ! class_exists(Kint::class)) { // In case that Kint is not loaded. + /** + * d function + * + * @param array $vars + * + * @return int + */ function d(...$vars) { return 0; @@ -51,6 +67,11 @@ function d(...$vars) /** * Provides a backtrace to the current execution point, from Kint. */ + /** + * trace function + * + * @return int + */ function trace() { Kint::$aliases[] = 'trace'; @@ -58,6 +79,11 @@ function trace() } } else { // In case that Kint is not loaded. + /** + * trace function + * + * @return int + */ function trace() { return 0; diff --git a/system/Helpers/test_helper.php b/system/Helpers/test_helper.php index fe6b06794ccd..809a7aabe71b 100644 --- a/system/Helpers/test_helper.php +++ b/system/Helpers/test_helper.php @@ -47,6 +47,8 @@ function fake($model, ?array $overrides = null, $persist = true) * Used within our test suite to mock certain system tools. * * @param string $className Fully qualified class name + * + * @return object */ function mock(string $className) { From 928629e5fe8f1afced299e2d3a3f65b53494542b Mon Sep 17 00:00:00 2001 From: chingyi lan Date: Fri, 4 Aug 2023 15:37:09 +0800 Subject: [PATCH 2/5] phpstan helpers kint_helper --- system/Helpers/kint_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Helpers/kint_helper.php b/system/Helpers/kint_helper.php index 1688c1746c2d..691f7e8b9fdb 100644 --- a/system/Helpers/kint_helper.php +++ b/system/Helpers/kint_helper.php @@ -70,7 +70,7 @@ function d(...$vars) /** * trace function * - * @return int + * @return int|string */ function trace() { From 40697116a58d7b69f08911b4491ffdce03b85f6b Mon Sep 17 00:00:00 2001 From: chingyi lan Date: Fri, 4 Aug 2023 15:50:23 +0800 Subject: [PATCH 3/5] phpstan kint_helper --- system/Helpers/kint_helper.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/system/Helpers/kint_helper.php b/system/Helpers/kint_helper.php index 691f7e8b9fdb..8dd7b5771098 100644 --- a/system/Helpers/kint_helper.php +++ b/system/Helpers/kint_helper.php @@ -67,11 +67,6 @@ function d(...$vars) /** * Provides a backtrace to the current execution point, from Kint. */ - /** - * trace function - * - * @return int|string - */ function trace() { Kint::$aliases[] = 'trace'; From e81a05dfd04f57012b44d03a636bc07001a83308 Mon Sep 17 00:00:00 2001 From: chingyi lan Date: Fri, 4 Aug 2023 16:04:45 +0800 Subject: [PATCH 4/5] return never --- system/Helpers/kint_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Helpers/kint_helper.php b/system/Helpers/kint_helper.php index 8dd7b5771098..9b33741053ac 100644 --- a/system/Helpers/kint_helper.php +++ b/system/Helpers/kint_helper.php @@ -18,7 +18,7 @@ * * @param array $vars * - * @return void + * @phpstan-return never * * @codeCoverageIgnore Can't be tested ... exits */ From 3c805e452b03978df7674fa0eed1b2e421ce384f Mon Sep 17 00:00:00 2001 From: chingyi lan Date: Fri, 4 Aug 2023 16:11:38 +0800 Subject: [PATCH 5/5] analyse no error. TT --- system/Helpers/kint_helper.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/system/Helpers/kint_helper.php b/system/Helpers/kint_helper.php index 9b33741053ac..eaa2e947bc96 100644 --- a/system/Helpers/kint_helper.php +++ b/system/Helpers/kint_helper.php @@ -67,6 +67,11 @@ function d(...$vars) /** * Provides a backtrace to the current execution point, from Kint. */ + /** + * trace function + * + * @return void + */ function trace() { Kint::$aliases[] = 'trace';