From 5ffb5636b2eae99afd6522eaba7e7809d8b939f5 Mon Sep 17 00:00:00 2001 From: Brandon Date: Wed, 26 Mar 2025 21:24:04 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Simplify=20the=20default=20Compo?= =?UTF-8?q?sers=20(#3250)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/View/Composers/App.php | 18 +------ app/View/Composers/Comments.php | 47 ++++--------------- app/View/Composers/Post.php | 21 +-------- resources/views/partials/comments.blade.php | 10 ++-- .../views/partials/content-page.blade.php | 2 +- .../views/partials/content-single.blade.php | 2 +- 6 files changed, 20 insertions(+), 80 deletions(-) diff --git a/app/View/Composers/App.php b/app/View/Composers/App.php index 0d870d4..e7f2008 100644 --- a/app/View/Composers/App.php +++ b/app/View/Composers/App.php @@ -16,23 +16,9 @@ class App extends Composer ]; /** - * Data to be passed to view before rendering. - * - * @return array + * Retrieve the site name. */ - public function with() - { - return [ - 'siteName' => $this->siteName(), - ]; - } - - /** - * Returns the site name. - * - * @return string - */ - public function siteName() + public function siteName(): string { return get_bloginfo('name', 'display'); } diff --git a/app/View/Composers/Comments.php b/app/View/Composers/Comments.php index 748d3a3..0f5f3fa 100644 --- a/app/View/Composers/Comments.php +++ b/app/View/Composers/Comments.php @@ -15,29 +15,10 @@ class Comments extends Composer 'partials.comments', ]; - /** - * Data to be passed to view before rendering. - * - * @return array - */ - public function with() - { - return [ - 'title' => $this->title(), - 'responses' => $this->responses(), - 'previous' => $this->previous(), - 'next' => $this->next(), - 'paginated' => $this->paginated(), - 'closed' => $this->closed(), - ]; - } - /** * The comment title. - * - * @return string */ - public function title() + public function title(): string { return sprintf( /* translators: %1$s is replaced with the number of comments and %2$s with the post title */ @@ -49,13 +30,11 @@ class Comments extends Composer /** * Retrieve the comments. - * - * @return string */ - public function responses() + public function responses(): ?string { if (! have_comments()) { - return; + return null; } return wp_list_comments([ @@ -67,13 +46,11 @@ class Comments extends Composer /** * The previous comments link. - * - * @return string */ - public function previous() + public function previous(): ?string { if (! get_previous_comments_link()) { - return; + return null; } return get_previous_comments_link( @@ -83,13 +60,11 @@ class Comments extends Composer /** * The next comments link. - * - * @return string */ - public function next() + public function next(): ?string { if (! get_next_comments_link()) { - return; + return null; } return get_next_comments_link( @@ -99,20 +74,16 @@ class Comments extends Composer /** * Determine if the comments are paginated. - * - * @return bool */ - public function paginated() + public function paginated(): bool { return get_comment_pages_count() > 1 && get_option('page_comments'); } /** * Determine if the comments are closed. - * - * @return bool */ - public function closed() + public function closed(): bool { return ! comments_open() && get_comments_number() != '0' && post_type_supports(get_post_type(), 'comments'); } diff --git a/app/View/Composers/Post.php b/app/View/Composers/Post.php index 3366b0d..baf65ba 100644 --- a/app/View/Composers/Post.php +++ b/app/View/Composers/Post.php @@ -17,25 +17,10 @@ class Post extends Composer 'partials.content-*', ]; - /** - * Data to be passed to view before rendering, but after merging. - * - * @return array - */ - public function override() - { - return [ - 'title' => $this->title(), - 'pagination' => $this->pagination(), - ]; - } - /** * Retrieve the post title. - * - * @return string */ - public function title() + public function title(): string { if ($this->view->name() !== 'partials.page-header') { return get_the_title(); @@ -70,10 +55,8 @@ class Post extends Composer /** * Retrieve the pagination links. - * - * @return string */ - public function pagination() + public function pagination(): string { return wp_link_pages([ 'echo' => 0, diff --git a/resources/views/partials/comments.blade.php b/resources/views/partials/comments.blade.php index 4ab83bd..09aa119 100644 --- a/resources/views/partials/comments.blade.php +++ b/resources/views/partials/comments.blade.php @@ -1,6 +1,6 @@ @if (! post_password_required())
- @if ($responses) + @if ($responses())

{!! $title !!}

@@ -9,16 +9,16 @@ {!! $responses !!} - @if ($paginated) + @if ($paginated())