From 2aa4bd54cc9edf4aa5a7cf3630239469ab8d6cb7 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Fri, 4 Aug 2023 00:50:01 +0800 Subject: [PATCH 1/4] Dev: Remove the `Pager`, `Publisher` and `RESTful` ignore errors in phpstan-baseline.php --- phpstan-baseline.php | 55 ------------------- system/Pager/Exceptions/PagerException.php | 4 +- system/Pager/Pager.php | 4 ++ system/Pager/PagerRenderer.php | 2 + .../Exceptions/PublisherException.php | 6 +- system/Publisher/Publisher.php | 2 +- system/RESTful/BaseResource.php | 4 ++ 7 files changed, 16 insertions(+), 61 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 2862ecaed635..030b2745071e 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1466,61 +1466,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Model.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Pager\\\\Exceptions\\\\PagerException\\:\\:forInvalidPaginationGroup\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Pager/Exceptions/PagerException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Pager\\\\Exceptions\\\\PagerException\\:\\:forInvalidTemplate\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Pager/Exceptions/PagerException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Pager\\\\Pager\\:\\:calculateCurrentPage\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Pager/Pager.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Pager\\\\Pager\\:\\:ensureGroup\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Pager/Pager.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Pager\\\\PagerRenderer\\:\\:updatePages\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Pager/PagerRenderer.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Publisher\\\\Exceptions\\\\PublisherException\\:\\:forCollision\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Publisher/Exceptions/PublisherException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Publisher\\\\Exceptions\\\\PublisherException\\:\\:forDestinationNotAllowed\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Publisher/Exceptions/PublisherException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Publisher\\\\Exceptions\\\\PublisherException\\:\\:forFileNotAllowed\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Publisher/Exceptions/PublisherException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Publisher\\\\Publisher\\:\\:verifyAllowed\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Publisher/Publisher.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\RESTful\\\\BaseResource\\:\\:initController\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/RESTful/BaseResource.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\RESTful\\\\BaseResource\\:\\:setModel\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/RESTful/BaseResource.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Router\\\\AutoRouter\\:\\:setDirectory\\(\\) has no return type specified\\.$#', 'count' => 1, diff --git a/system/Pager/Exceptions/PagerException.php b/system/Pager/Exceptions/PagerException.php index b1cb6072816f..cc37ecfba967 100644 --- a/system/Pager/Exceptions/PagerException.php +++ b/system/Pager/Exceptions/PagerException.php @@ -15,12 +15,12 @@ class PagerException extends FrameworkException { - public static function forInvalidTemplate(?string $template = null) + public static function forInvalidTemplate(?string $template = null): PagerException { return new static(lang('Pager.invalidTemplate', [$template])); } - public static function forInvalidPaginationGroup(?string $group = null) + public static function forInvalidPaginationGroup(?string $group = null): PagerException { return new static(lang('Pager.invalidPaginationGroup', [$group])); } diff --git a/system/Pager/Pager.php b/system/Pager/Pager.php index 2c0179a69dc3..7525735f9961 100644 --- a/system/Pager/Pager.php +++ b/system/Pager/Pager.php @@ -388,6 +388,8 @@ public function only(array $queries): self * Ensures that an array exists for the group specified. * * @param int $perPage + * + * @return void */ protected function ensureGroup(string $group, ?int $perPage = null) { @@ -414,6 +416,8 @@ protected function ensureGroup(string $group, ?int $perPage = null) /** * Calculating the current page + * + * @return void */ protected function calculateCurrentPage(string $group) { diff --git a/system/Pager/PagerRenderer.php b/system/Pager/PagerRenderer.php index 9206a482323b..024ffd095673 100644 --- a/system/Pager/PagerRenderer.php +++ b/system/Pager/PagerRenderer.php @@ -289,6 +289,8 @@ public function links(): array * to show. * * @param int|null $count The new "surroundCount" + * + * @return void */ protected function updatePages(?int $count = null) { diff --git a/system/Publisher/Exceptions/PublisherException.php b/system/Publisher/Exceptions/PublisherException.php index 535d3a757d15..cdb3e41f8ac5 100644 --- a/system/Publisher/Exceptions/PublisherException.php +++ b/system/Publisher/Exceptions/PublisherException.php @@ -26,7 +26,7 @@ class PublisherException extends FrameworkException * @param string $from The source file * @param string $to The destination file */ - public static function forCollision(string $from, string $to) + public static function forCollision(string $from, string $to): PublisherException { return new static(lang('Publisher.collision', [filetype($to), $from, $to])); } @@ -34,7 +34,7 @@ public static function forCollision(string $from, string $to) /** * Throws when given a destination that is not in the list of allowed directories. */ - public static function forDestinationNotAllowed(string $destination) + public static function forDestinationNotAllowed(string $destination): PublisherException { return new static(lang('Publisher.destinationNotAllowed', [$destination])); } @@ -42,7 +42,7 @@ public static function forDestinationNotAllowed(string $destination) /** * Throws when a file fails to match the allowed pattern for its destination. */ - public static function forFileNotAllowed(string $file, string $directory, string $pattern) + public static function forFileNotAllowed(string $file, string $directory, string $pattern): PublisherException { return new static(lang('Publisher.fileNotAllowed', [$file, $directory, $pattern])); } diff --git a/system/Publisher/Publisher.php b/system/Publisher/Publisher.php index 82948b8378c1..e40a14c88905 100644 --- a/system/Publisher/Publisher.php +++ b/system/Publisher/Publisher.php @@ -466,7 +466,7 @@ public function addLineBefore(string $file, string $line, string $before): bool /** * Verify this is an allowed file for its destination. */ - private function verifyAllowed(string $from, string $to) + private function verifyAllowed(string $from, string $to): void { // Verify this is an allowed file for its destination foreach ($this->restrictions as $directory => $pattern) { diff --git a/system/RESTful/BaseResource.php b/system/RESTful/BaseResource.php index 108c63ce9be6..1c21f65da860 100644 --- a/system/RESTful/BaseResource.php +++ b/system/RESTful/BaseResource.php @@ -39,6 +39,8 @@ abstract class BaseResource extends Controller /** * Constructor. + * + * @return void */ public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { @@ -52,6 +54,8 @@ public function initController(RequestInterface $request, ResponseInterface $res * Given either the name or the object, determine the other. * * @param object|string|null $which + * + * @return void */ public function setModel($which = null) { From fbd6d94a50b6f91d3295f039bfb5eaed4cd19562 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Fri, 4 Aug 2023 13:25:02 +0800 Subject: [PATCH 2/4] Dev: change the return type for the exception. --- system/Publisher/Exceptions/PublisherException.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/Publisher/Exceptions/PublisherException.php b/system/Publisher/Exceptions/PublisherException.php index cdb3e41f8ac5..ce457b70f99c 100644 --- a/system/Publisher/Exceptions/PublisherException.php +++ b/system/Publisher/Exceptions/PublisherException.php @@ -26,7 +26,7 @@ class PublisherException extends FrameworkException * @param string $from The source file * @param string $to The destination file */ - public static function forCollision(string $from, string $to): PublisherException + public static function forCollision(string $from, string $to): self { return new static(lang('Publisher.collision', [filetype($to), $from, $to])); } @@ -34,7 +34,7 @@ public static function forCollision(string $from, string $to): PublisherExceptio /** * Throws when given a destination that is not in the list of allowed directories. */ - public static function forDestinationNotAllowed(string $destination): PublisherException + public static function forDestinationNotAllowed(string $destination): self { return new static(lang('Publisher.destinationNotAllowed', [$destination])); } @@ -42,7 +42,7 @@ public static function forDestinationNotAllowed(string $destination): PublisherE /** * Throws when a file fails to match the allowed pattern for its destination. */ - public static function forFileNotAllowed(string $file, string $directory, string $pattern): PublisherException + public static function forFileNotAllowed(string $file, string $directory, string $pattern): self { return new static(lang('Publisher.fileNotAllowed', [$file, $directory, $pattern])); } From adbfbf79c236668eb42179d0ba81064dd20bbf34 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Fri, 4 Aug 2023 13:26:03 +0800 Subject: [PATCH 3/4] Dev: change the return type for the pager exception. --- system/Pager/Exceptions/PagerException.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Pager/Exceptions/PagerException.php b/system/Pager/Exceptions/PagerException.php index cc37ecfba967..db6868ee945f 100644 --- a/system/Pager/Exceptions/PagerException.php +++ b/system/Pager/Exceptions/PagerException.php @@ -15,12 +15,12 @@ class PagerException extends FrameworkException { - public static function forInvalidTemplate(?string $template = null): PagerException + public static function forInvalidTemplate(?string $template = null): self { return new static(lang('Pager.invalidTemplate', [$template])); } - public static function forInvalidPaginationGroup(?string $group = null): PagerException + public static function forInvalidPaginationGroup(?string $group = null): self { return new static(lang('Pager.invalidPaginationGroup', [$group])); } From 3eb083c79cf4f5f2011b316efcef380cde6ac0cd Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Fri, 4 Aug 2023 21:35:22 +0800 Subject: [PATCH 4/4] Dev: Define the exception. --- system/Pager/Exceptions/PagerException.php | 14 ++++++++++++-- system/Publisher/Exceptions/PublisherException.php | 12 +++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/system/Pager/Exceptions/PagerException.php b/system/Pager/Exceptions/PagerException.php index db6868ee945f..6f1032f7281d 100644 --- a/system/Pager/Exceptions/PagerException.php +++ b/system/Pager/Exceptions/PagerException.php @@ -15,12 +15,22 @@ class PagerException extends FrameworkException { - public static function forInvalidTemplate(?string $template = null): self + /** + * Throws when the template is invalid. + * + * @return static + */ + public static function forInvalidTemplate(?string $template = null) { return new static(lang('Pager.invalidTemplate', [$template])); } - public static function forInvalidPaginationGroup(?string $group = null): self + /** + * Throws when the group is invalid. + * + * @return static + */ + public static function forInvalidPaginationGroup(?string $group = null) { return new static(lang('Pager.invalidPaginationGroup', [$group])); } diff --git a/system/Publisher/Exceptions/PublisherException.php b/system/Publisher/Exceptions/PublisherException.php index ce457b70f99c..5204897c975e 100644 --- a/system/Publisher/Exceptions/PublisherException.php +++ b/system/Publisher/Exceptions/PublisherException.php @@ -25,24 +25,30 @@ class PublisherException extends FrameworkException * * @param string $from The source file * @param string $to The destination file + * + * @return static */ - public static function forCollision(string $from, string $to): self + public static function forCollision(string $from, string $to) { return new static(lang('Publisher.collision', [filetype($to), $from, $to])); } /** * Throws when given a destination that is not in the list of allowed directories. + * + * @return static */ - public static function forDestinationNotAllowed(string $destination): self + public static function forDestinationNotAllowed(string $destination) { return new static(lang('Publisher.destinationNotAllowed', [$destination])); } /** * Throws when a file fails to match the allowed pattern for its destination. + * + * @return static */ - public static function forFileNotAllowed(string $file, string $directory, string $pattern): self + public static function forFileNotAllowed(string $file, string $directory, string $pattern) { return new static(lang('Publisher.fileNotAllowed', [$file, $directory, $pattern])); }