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.
This commit is contained in:
parent
d15450d2f0
commit
4f3d9ff015
8 changed files with 16 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}"),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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}"),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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}"),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public function broadcastAs(): string
|
|||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PrivateChannel('workspace.'.$this->workspaceId),
|
||||
new PrivateChannel("workspace.{$this->workspaceId}"),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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}"),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 () {
|
||||
|
|
|
|||
|
|
@ -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 () {
|
||||
|
|
|
|||
Loading…
Reference in a new issue