From 26d7b48eeb04409f5339ce0125ba0ff8fc32c2d5 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Fri, 4 Aug 2023 00:36:41 +0800 Subject: [PATCH 1/7] Dev: Remove the `Honeypot` and `I18n` ignore errors in phpstan-baseline.php --- phpstan-baseline.php | 85 ++++++++++++++----- .../Honeypot/Exceptions/HoneypotException.php | 8 +- system/Honeypot/Honeypot.php | 4 + system/I18n/TimeTrait.php | 4 + 4 files changed, 77 insertions(+), 24 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index c31e87d7cee4..456b8710f214 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1147,54 +1147,99 @@ 'path' => __DIR__ . '/system/Helpers/filesystem_helper.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Honeypot\\\\Exceptions\\\\HoneypotException\\:\\:forNoHiddenValue\\(\\) has no return type specified\\.$#', + 'message' => '#^Function d\\(\\) has no return type specified\\.$#', 'count' => 1, - 'path' => __DIR__ . '/system/Honeypot/Exceptions/HoneypotException.php', + 'path' => __DIR__ . '/system/Helpers/kint_helper.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Honeypot\\\\Exceptions\\\\HoneypotException\\:\\:forNoNameField\\(\\) has no return type specified\\.$#', + 'message' => '#^Function d\\(\\) has parameter \\$vars with no type specified\\.$#', 'count' => 1, - 'path' => __DIR__ . '/system/Honeypot/Exceptions/HoneypotException.php', + 'path' => __DIR__ . '/system/Helpers/kint_helper.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Honeypot\\\\Exceptions\\\\HoneypotException\\:\\:forNoTemplate\\(\\) has no return type specified\\.$#', + '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\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forEXIFUnsupported\\(\\) has no return type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forFileNotSupported\\(\\) has no return type specified\\.$#', 'count' => 1, - 'path' => __DIR__ . '/system/Honeypot/Exceptions/HoneypotException.php', + 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Honeypot\\\\Exceptions\\\\HoneypotException\\:\\:isBot\\(\\) has no return type specified\\.$#', + 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forImageProcessFailed\\(\\) has no return type specified\\.$#', 'count' => 1, - 'path' => __DIR__ . '/system/Honeypot/Exceptions/HoneypotException.php', + 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Honeypot\\\\Honeypot\\:\\:attachHoneypot\\(\\) has no return type specified\\.$#', + 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidDirection\\(\\) has no return type specified\\.$#', 'count' => 1, - 'path' => __DIR__ . '/system/Honeypot/Honeypot.php', + 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Honeypot\\\\Honeypot\\:\\:hasContent\\(\\) has no return type specified\\.$#', + 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidImageCreate\\(\\) has no return type specified\\.$#', 'count' => 1, - 'path' => __DIR__ . '/system/Honeypot/Honeypot.php', + 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\I18n\\\\Time\\:\\:setTestNow\\(\\) has no return type specified\\.$#', + 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidImageLibraryPath\\(\\) has no return type specified\\.$#', 'count' => 1, - 'path' => __DIR__ . '/system/I18n/Time.php', + 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\I18n\\\\Time\\:\\:toDateTimeString\\(\\) has no return type specified\\.$#', + 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidPath\\(\\) has no return type specified\\.$#', 'count' => 1, - 'path' => __DIR__ . '/system/I18n/Time.php', + 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\I18n\\\\TimeLegacy\\:\\:setTestNow\\(\\) has no return type specified\\.$#', + 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forMissingAngle\\(\\) has no return type specified\\.$#', 'count' => 1, - 'path' => __DIR__ . '/system/I18n/TimeLegacy.php', + 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\I18n\\\\TimeLegacy\\:\\:toDateTimeString\\(\\) has no return type specified\\.$#', + 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forMissingImage\\(\\) has no return type specified\\.$#', 'count' => 1, - 'path' => __DIR__ . '/system/I18n/TimeLegacy.php', + 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forSaveFailed\\(\\) has no return type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:_text\\(\\) has no return type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Images/Handlers/BaseHandler.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:ensureResource\\(\\) has no return type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Images/Handlers/BaseHandler.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:reproportion\\(\\) has no return type specified\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Images/Handlers/BaseHandler.php', ]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:\\$image \\(CodeIgniter\\\\Images\\\\Image\\) in empty\\(\\) is not falsy\\.$#', diff --git a/system/Honeypot/Exceptions/HoneypotException.php b/system/Honeypot/Exceptions/HoneypotException.php index 8d8510eca8fa..e6d1437e784a 100644 --- a/system/Honeypot/Exceptions/HoneypotException.php +++ b/system/Honeypot/Exceptions/HoneypotException.php @@ -16,22 +16,22 @@ class HoneypotException extends ConfigException implements ExceptionInterface { - public static function forNoTemplate() + public static function forNoTemplate(): HoneypotException { return new static(lang('Honeypot.noTemplate')); } - public static function forNoNameField() + public static function forNoNameField(): HoneypotException { return new static(lang('Honeypot.noNameField')); } - public static function forNoHiddenValue() + public static function forNoHiddenValue(): HoneypotException { return new static(lang('Honeypot.noHiddenValue')); } - public static function isBot() + public static function isBot(): HoneypotException { return new static(lang('Honeypot.theClientIsABot')); } diff --git a/system/Honeypot/Honeypot.php b/system/Honeypot/Honeypot.php index 7ab0cd36737e..6e08c9df8bfe 100644 --- a/system/Honeypot/Honeypot.php +++ b/system/Honeypot/Honeypot.php @@ -59,6 +59,8 @@ public function __construct(HoneypotConfig $config) /** * Checks the request if honeypot field has data. + * + * @return bool */ public function hasContent(RequestInterface $request) { @@ -69,6 +71,8 @@ public function hasContent(RequestInterface $request) /** * Attaches Honeypot template to response. + * + * @return void */ public function attachHoneypot(ResponseInterface $response) { diff --git a/system/I18n/TimeTrait.php b/system/I18n/TimeTrait.php index 5c41618f6861..7f2068b7a30c 100644 --- a/system/I18n/TimeTrait.php +++ b/system/I18n/TimeTrait.php @@ -320,6 +320,8 @@ public function toDateTime() * @param DateTimeInterface|self|string|null $datetime * @param DateTimeZone|string|null $timezone * + * @return void + * * @throws Exception */ public static function setTestNow($datetime = null, $timezone = null, ?string $locale = null) @@ -845,6 +847,8 @@ public function subYears(int $years) /** * Returns the localized value of the date in the format 'Y-m-d H:i:s' * + * @return false|string + * * @throws Exception */ public function toDateTimeString() From 39d09d91edaf698a514ea8d932562ddfe0529c42 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Fri, 4 Aug 2023 13:27:15 +0800 Subject: [PATCH 2/7] Dev: change the return type for the honeypot exception. --- system/Honeypot/Exceptions/HoneypotException.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/Honeypot/Exceptions/HoneypotException.php b/system/Honeypot/Exceptions/HoneypotException.php index e6d1437e784a..f3c88c0f0d0e 100644 --- a/system/Honeypot/Exceptions/HoneypotException.php +++ b/system/Honeypot/Exceptions/HoneypotException.php @@ -16,22 +16,22 @@ class HoneypotException extends ConfigException implements ExceptionInterface { - public static function forNoTemplate(): HoneypotException + public static function forNoTemplate(): self { return new static(lang('Honeypot.noTemplate')); } - public static function forNoNameField(): HoneypotException + public static function forNoNameField(): self { return new static(lang('Honeypot.noNameField')); } - public static function forNoHiddenValue(): HoneypotException + public static function forNoHiddenValue(): self { return new static(lang('Honeypot.noHiddenValue')); } - public static function isBot(): HoneypotException + public static function isBot(): self { return new static(lang('Honeypot.theClientIsABot')); } From 31a83ed04f868b4e86e725368d0e382245984649 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Fri, 4 Aug 2023 20:37:42 +0800 Subject: [PATCH 3/7] Dev: Define the comment of exception. --- .../Honeypot/Exceptions/HoneypotException.php | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/system/Honeypot/Exceptions/HoneypotException.php b/system/Honeypot/Exceptions/HoneypotException.php index f3c88c0f0d0e..2aeb44930901 100644 --- a/system/Honeypot/Exceptions/HoneypotException.php +++ b/system/Honeypot/Exceptions/HoneypotException.php @@ -16,22 +16,42 @@ class HoneypotException extends ConfigException implements ExceptionInterface { - public static function forNoTemplate(): self + /** + * Thrown when the template value of config is empty. + * + * @return self + */ + public static function forNoTemplate() { return new static(lang('Honeypot.noTemplate')); } - public static function forNoNameField(): self + /** + * Thrown when the name value of config is empty. + * + * @return self + */ + public static function forNoNameField() { return new static(lang('Honeypot.noNameField')); } - public static function forNoHiddenValue(): self + /** + * Thrown when the hidden value of config is false. + * + * @return self + */ + public static function forNoHiddenValue() { return new static(lang('Honeypot.noHiddenValue')); } - public static function isBot(): self + /** + * Thrown when there are no data in the request of honeypot field. + * + * @return self + */ + public static function isBot() { return new static(lang('Honeypot.theClientIsABot')); } From 25248a5c41ea3334d4e23d5b72caac156fa64600 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Fri, 4 Aug 2023 20:43:03 +0800 Subject: [PATCH 4/7] Dev: change the return type. --- system/Honeypot/Exceptions/HoneypotException.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/Honeypot/Exceptions/HoneypotException.php b/system/Honeypot/Exceptions/HoneypotException.php index 2aeb44930901..31d13151e980 100644 --- a/system/Honeypot/Exceptions/HoneypotException.php +++ b/system/Honeypot/Exceptions/HoneypotException.php @@ -19,7 +19,7 @@ class HoneypotException extends ConfigException implements ExceptionInterface /** * Thrown when the template value of config is empty. * - * @return self + * @return static */ public static function forNoTemplate() { @@ -29,7 +29,7 @@ public static function forNoTemplate() /** * Thrown when the name value of config is empty. * - * @return self + * @return static */ public static function forNoNameField() { @@ -39,7 +39,7 @@ public static function forNoNameField() /** * Thrown when the hidden value of config is false. * - * @return self + * @return static */ public static function forNoHiddenValue() { @@ -49,7 +49,7 @@ public static function forNoHiddenValue() /** * Thrown when there are no data in the request of honeypot field. * - * @return self + * @return static */ public static function isBot() { From e3dff64690aac1618e1108d288974a26e6ad4c62 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Mon, 7 Aug 2023 19:23:45 +0800 Subject: [PATCH 5/7] Dev: fix the rebase error. --- phpstan-baseline.php | 99 ++------------------------------------------ 1 file changed, 3 insertions(+), 96 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 456b8710f214..41400c987390 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1,4 +1,6 @@ - 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\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forEXIFUnsupported\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forFileNotSupported\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forImageProcessFailed\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidDirection\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidImageCreate\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidImageLibraryPath\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidPath\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forMissingAngle\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forMissingImage\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forSaveFailed\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:_text\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Handlers/BaseHandler.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:ensureResource\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Handlers/BaseHandler.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:reproportion\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Images/Handlers/BaseHandler.php', -]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:\\$image \\(CodeIgniter\\\\Images\\\\Image\\) in empty\\(\\) is not falsy\\.$#', 'count' => 1, From 01703f3363fe21419b025e4fc0bc944cfb5b73cd Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Mon, 7 Aug 2023 19:25:13 +0800 Subject: [PATCH 6/7] Dev: fix the cs-fix. --- phpstan-baseline.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 41400c987390..985edbd2883e 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1,6 +1,4 @@ - Date: Mon, 7 Aug 2023 19:26:17 +0800 Subject: [PATCH 7/7] Dev: fix the cs. --- phpstan-baseline.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 985edbd2883e..94afb2a65be7 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1,4 +1,4 @@ -