Skip to content

Commit cba9185

Browse files
committed
Updates
1 parent d7ebed1 commit cba9185

23 files changed

+1718
-1739
lines changed

app/Exceptions/CannotLikeItem.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
7+
final class CannotLikeItem extends Exception
8+
{
9+
public static function alreadyLiked(string $item): self
10+
{
11+
return new self("The {$item} cannot be liked multiple times.");
12+
}
13+
}

app/Exceptions/CannotLikeReplyMultipleTimes.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

app/Exceptions/CannotLikeThreadMultipleTimes.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

app/Helpers/ReceivesReplies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function latestReplies(int $amount = 5)
2525

2626
public function deleteReplies()
2727
{
28-
// We need to explicitly iterate over the repies and delete them
28+
// We need to explicitly iterate over the replies and delete them
2929
// separately because all related models need to be deleted.
3030
foreach ($this->repliesRelation()->get() as $reply) {
3131
$reply->delete();

app/Http/Controllers/Forum/ThreadsController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,16 @@ public function unsubscribe(Request $request, Thread $thread)
136136
return redirect()->route('thread', $thread->slug());
137137
}
138138

139-
public function like(Thread $thread)
139+
public function like(Request $request, Thread $thread)
140140
{
141-
$this->dispatchNow(new LikeThread($thread, auth()->user()));
141+
$this->dispatchNow(new LikeThread($thread, $request->user()));
142142

143143
return redirect()->route('thread', $thread->slug());
144144
}
145145

146-
public function unlike(Thread $thread)
146+
public function unlike(Request $request, Thread $thread)
147147
{
148-
$this->dispatchNow(new UnlikeThread($thread, auth()->user()));
148+
$this->dispatchNow(new UnlikeThread($thread, $request->user()));
149149

150150
return redirect()->route('thread', $thread->slug());
151151
}

app/Http/Controllers/ReplyController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use App\Policies\ReplyPolicy;
1717
use Illuminate\Auth\Middleware\Authenticate;
1818
use Illuminate\Http\RedirectResponse;
19+
use Illuminate\Http\Request;
1920

2021
class ReplyController extends Controller
2122
{
@@ -64,17 +65,17 @@ public function delete(Reply $reply)
6465
return $this->redirectToReplyAble($reply->replyAble());
6566
}
6667

67-
public function like(Reply $reply)
68+
public function like(Request $request, Reply $reply)
6869
{
69-
$this->dispatchNow(new LikeReply($reply, auth()->user()));
70+
$this->dispatchNow(new LikeReply($reply, $request->user()));
7071

7172
return redirect()
7273
->to(route('thread', $reply->replyAble()->slug())."#{$reply->id}");
7374
}
7475

75-
public function unlike(Reply $reply)
76+
public function unlike(Request $request, Reply $reply)
7677
{
77-
$this->dispatchNow(new UnlikeReply($reply, auth()->user()));
78+
$this->dispatchNow(new UnlikeReply($reply, $request->user()));
7879

7980
return redirect()
8081
->to(route('thread', $reply->replyAble()->slug())."#{$reply->id}");

app/Jobs/LikeReply.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace App\Jobs;
44

5-
use App\Exceptions\CannotLikeReplyMultipleTimes;
5+
use App\Exceptions\CannotLikeItem;
66
use App\Models\Reply;
77
use App\User;
88

9-
class LikeReply
9+
final class LikeReply
1010
{
1111
/**
1212
* @var \App\Models\Reply
@@ -18,28 +18,19 @@ class LikeReply
1818
*/
1919
private $user;
2020

21-
/**
22-
* Create a new job instance.
23-
*
24-
* @param \App\Models\Reply $reply
25-
* @param \App\User $user
26-
*/
2721
public function __construct(Reply $reply, User $user)
2822
{
2923
$this->reply = $reply;
3024
$this->user = $user;
3125
}
3226

3327
/**
34-
* Execute the job.
35-
*
36-
* @return void
37-
* @throws \App\Exceptions\CannotLikeReplyMultipleTimes
28+
* @throws \App\Exceptions\CannotLikeItem
3829
*/
39-
public function handle()
30+
public function handle(): void
4031
{
4132
if ($this->reply->isLikedBy($this->user)) {
42-
throw new CannotLikeReplyMultipleTimes();
33+
throw CannotLikeItem::alreadyLiked('reply');
4334
}
4435

4536
$this->reply->likedBy($this->user);

app/Jobs/LikeThread.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace App\Jobs;
44

5-
use App\Exceptions\CannotLikeThreadMultipleTimes;
5+
use App\Exceptions\CannotLikeItem;
66
use App\Models\Thread;
77
use App\User;
88

9-
class LikeThread
9+
final class LikeThread
1010
{
1111
/**
1212
* @var \App\Models\Thread
@@ -18,28 +18,19 @@ class LikeThread
1818
*/
1919
private $user;
2020

21-
/**
22-
* Create a new job instance.
23-
*
24-
* @param \App\Models\Thread $thread
25-
* @param \App\User $user
26-
*/
2721
public function __construct(Thread $thread, User $user)
2822
{
2923
$this->thread = $thread;
3024
$this->user = $user;
3125
}
3226

3327
/**
34-
* Execute the job.
35-
*
36-
* @return void
37-
* @throws \App\Exceptions\CannotLikeThreadMultipleTimes
28+
* @throws \App\Exceptions\CannotLikeItem
3829
*/
39-
public function handle()
30+
public function handle(): void
4031
{
4132
if ($this->thread->isLikedBy($this->user)) {
42-
throw new CannotLikeThreadMultipleTimes();
33+
throw CannotLikeItem::alreadyLiked('thread');
4334
}
4435

4536
$this->thread->likedBy($this->user);

app/Jobs/UnlikeReply.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use App\Models\Reply;
66
use App\User;
77

8-
class UnlikeReply
8+
final class UnlikeReply
99
{
1010
/**
1111
* @var \App\Models\Reply
@@ -17,24 +17,13 @@ class UnlikeReply
1717
*/
1818
private $user;
1919

20-
/**
21-
* Create a new job instance.
22-
*
23-
* @param \App\Models\Reply $reply
24-
* @param \App\User $user
25-
*/
2620
public function __construct(Reply $reply, User $user)
2721
{
2822
$this->reply = $reply;
2923
$this->user = $user;
3024
}
3125

32-
/**
33-
* Execute the job.
34-
*
35-
* @return void
36-
*/
37-
public function handle()
26+
public function handle(): void
3827
{
3928
$this->reply->dislikedBy($this->user);
4029
}

app/Jobs/UnlikeThread.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use App\Models\Thread;
66
use App\User;
77

8-
class UnlikeThread
8+
final class UnlikeThread
99
{
1010
/**
1111
* @var \App\Models\Thread
@@ -17,24 +17,13 @@ class UnlikeThread
1717
*/
1818
private $user;
1919

20-
/**
21-
* Create a new job instance.
22-
*
23-
* @param \App\Models\Thread $thread
24-
* @param \App\User $user
25-
*/
2620
public function __construct(Thread $thread, User $user)
2721
{
2822
$this->thread = $thread;
2923
$this->user = $user;
3024
}
3125

32-
/**
33-
* Execute the job.
34-
*
35-
* @return void
36-
*/
37-
public function handle()
26+
public function handle(): void
3827
{
3928
$this->thread->dislikedBy($this->user);
4029
}

0 commit comments

Comments
 (0)