From 4f3d9ff01553c58474b15ebc1c9eb0162cab6daf Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Fri, 8 May 2026 19:22:01 -0300 Subject: [PATCH] refactor: prefer string interpolation over concatenation for channel names Convert all 'foo.'.$bar style concatenations to "foo.{$bar}" interpolation in event broadcast channels (PostCreated, PostDeleted, PostCommentCreated, PostPlatformStatusUpdated, NotificationCreated) and the related event tests. Document the convention in CLAUDE.md so new code follows the pattern. --- CLAUDE.md | 7 +++++++ app/Events/NotificationCreated.php | 2 +- app/Events/PostCommentCreated.php | 2 +- app/Events/PostCreated.php | 2 +- app/Events/PostDeleted.php | 2 +- app/Events/PostPlatformStatusUpdated.php | 4 ++-- tests/Unit/Events/PostCreatedTest.php | 2 +- tests/Unit/Events/PostPlatformStatusUpdatedTest.php | 4 ++-- 8 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index a5a46144..651d0c6f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -295,6 +295,13 @@ ## API Response Status Codes - When returning JSON responses with explicit status codes, always use `Symfony\Component\HttpFoundation\Response` constants instead of magic numbers. - Example: `Response::HTTP_CREATED` instead of `201`, `Response::HTTP_NO_CONTENT` instead of `204`. +## String Interpolation + +- When injecting variables into strings, prefer **double-quoted interpolation** with curly braces over concatenation with `.`. + - PHP: `"workspace.{$workspace->id}"` instead of `'workspace.'.$workspace->id`. + - Use curly braces `{}` even for simple variables to keep the boundary explicit and to allow object/array access without ambiguity. + - Single quotes are still preferred when the string has no interpolation. + ## TryPost.it Documentation - All our documentation to final user it's under https://docs.trypost.it diff --git a/app/Events/NotificationCreated.php b/app/Events/NotificationCreated.php index 416d35e5..61ab125b 100644 --- a/app/Events/NotificationCreated.php +++ b/app/Events/NotificationCreated.php @@ -24,7 +24,7 @@ public function broadcastAs(): string public function broadcastOn(): array { return [ - new PrivateChannel('workspace.'.$this->notification->workspace_id.'.user.'.$this->notification->user_id), + new PrivateChannel("workspace.{$this->notification->workspace_id}.user.{$this->notification->user_id}"), ]; } diff --git a/app/Events/PostCommentCreated.php b/app/Events/PostCommentCreated.php index f0e0140d..d2f50f70 100644 --- a/app/Events/PostCommentCreated.php +++ b/app/Events/PostCommentCreated.php @@ -26,7 +26,7 @@ public function broadcastAs(): string public function broadcastOn(): array { return [ - new PrivateChannel('post.'.$this->comment->post_id), + new PrivateChannel("post.{$this->comment->post_id}"), ]; } diff --git a/app/Events/PostCreated.php b/app/Events/PostCreated.php index 060e81b9..013f20d5 100644 --- a/app/Events/PostCreated.php +++ b/app/Events/PostCreated.php @@ -25,7 +25,7 @@ public function broadcastAs(): string public function broadcastOn(): array { return [ - new PrivateChannel('workspace.'.$this->post->workspace_id), + new PrivateChannel("workspace.{$this->post->workspace_id}"), ]; } diff --git a/app/Events/PostDeleted.php b/app/Events/PostDeleted.php index b33bbe51..75fca6e7 100644 --- a/app/Events/PostDeleted.php +++ b/app/Events/PostDeleted.php @@ -26,7 +26,7 @@ public function broadcastAs(): string public function broadcastOn(): array { return [ - new PrivateChannel('workspace.'.$this->workspaceId), + new PrivateChannel("workspace.{$this->workspaceId}"), ]; } diff --git a/app/Events/PostPlatformStatusUpdated.php b/app/Events/PostPlatformStatusUpdated.php index 6d2544f6..b4f540c3 100644 --- a/app/Events/PostPlatformStatusUpdated.php +++ b/app/Events/PostPlatformStatusUpdated.php @@ -25,8 +25,8 @@ public function broadcastAs(): string public function broadcastOn(): array { return [ - new PrivateChannel('post.'.$this->postPlatform->post_id), - new PrivateChannel('workspace.'.$this->postPlatform->post->workspace_id), + new PrivateChannel("post.{$this->postPlatform->post_id}"), + new PrivateChannel("workspace.{$this->postPlatform->post->workspace_id}"), ]; } diff --git a/tests/Unit/Events/PostCreatedTest.php b/tests/Unit/Events/PostCreatedTest.php index df664bf8..33069d9e 100644 --- a/tests/Unit/Events/PostCreatedTest.php +++ b/tests/Unit/Events/PostCreatedTest.php @@ -21,7 +21,7 @@ expect($channels)->toHaveCount(1); expect($channels[0])->toBeInstanceOf(PrivateChannel::class); - expect($channels[0]->name)->toBe('private-workspace.'.$workspace->id); + expect($channels[0]->name)->toBe("private-workspace.{$workspace->id}"); }); test('event broadcasts with the post id', function () { diff --git a/tests/Unit/Events/PostPlatformStatusUpdatedTest.php b/tests/Unit/Events/PostPlatformStatusUpdatedTest.php index 6ab0de1c..c753e0e2 100644 --- a/tests/Unit/Events/PostPlatformStatusUpdatedTest.php +++ b/tests/Unit/Events/PostPlatformStatusUpdatedTest.php @@ -34,9 +34,9 @@ expect($channels)->toHaveCount(2); expect($channels[0])->toBeInstanceOf(PrivateChannel::class); - expect($channels[0]->name)->toBe('private-post.'.$this->post->id); + expect($channels[0]->name)->toBe("private-post.{$this->post->id}"); expect($channels[1])->toBeInstanceOf(PrivateChannel::class); - expect($channels[1]->name)->toBe('private-workspace.'.$this->workspace->id); + expect($channels[1]->name)->toBe("private-workspace.{$this->workspace->id}"); }); test('event broadcasts with the post id', function () {