chore: code refactor via rector
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Livewire\Dashboard;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketResponse;
|
||||
use Exception;
|
||||
use Livewire\Component;
|
||||
use Request;
|
||||
use Str;
|
||||
|
||||
class Support extends Component
|
||||
{
|
||||
@@ -25,7 +25,7 @@ class Support extends Component
|
||||
|
||||
public $closed = 0;
|
||||
|
||||
public function store()
|
||||
public function store(): void
|
||||
{
|
||||
$this->validate([
|
||||
'subject' => 'required|string|max:255',
|
||||
@@ -33,7 +33,7 @@ class Support extends Component
|
||||
]);
|
||||
|
||||
try {
|
||||
$ticket = Ticket::create([
|
||||
$ticket = Ticket::query()->create([
|
||||
'user_id' => auth()->id(),
|
||||
'ticket_id' => strtoupper(Str::random(6)),
|
||||
'subject' => $this->subject,
|
||||
@@ -47,13 +47,13 @@ class Support extends Component
|
||||
$this->tickets = Ticket::with('responses')
|
||||
->where('user_id', auth()->id())
|
||||
->get();
|
||||
} catch (Exception $exception) {
|
||||
} catch (Exception) {
|
||||
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Something went wrong!']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function reply($ticket_id)
|
||||
public function reply($ticket_id): void
|
||||
{
|
||||
$this->validate([
|
||||
'response' => 'required|string',
|
||||
@@ -67,14 +67,14 @@ class Support extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
$ticket = Ticket::find($ticket_id);
|
||||
$ticket = Ticket::query()->find($ticket_id);
|
||||
if (! $ticket) {
|
||||
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Ticket not found.']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
TicketResponse::create([
|
||||
TicketResponse::query()->create([
|
||||
'ticket_id' => $ticket_id,
|
||||
'user_id' => auth()->id(),
|
||||
'response' => $this->response,
|
||||
@@ -90,20 +90,20 @@ class Support extends Component
|
||||
->where('user_id', auth()->id())
|
||||
->get();
|
||||
|
||||
} catch (Exception $exception) {
|
||||
} catch (Exception) {
|
||||
session()->flash('error', 'Something went wrong!');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function close($ticket_id)
|
||||
public function close($ticket_id): void
|
||||
{
|
||||
if (! is_numeric($ticket_id)) {
|
||||
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Invalid ticket ID.']);
|
||||
|
||||
return;
|
||||
}
|
||||
$ticket = Ticket::find($ticket_id);
|
||||
$ticket = Ticket::query()->find($ticket_id);
|
||||
if (! $ticket) {
|
||||
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Ticket not found.']);
|
||||
|
||||
@@ -119,7 +119,7 @@ class Support extends Component
|
||||
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'This ticket has been closed!']);
|
||||
}
|
||||
|
||||
public function mount()
|
||||
public function mount(): void
|
||||
{
|
||||
$this->tickets = Ticket::with('responses')
|
||||
->where('user_id', auth()->id())
|
||||
@@ -127,15 +127,11 @@ class Support extends Component
|
||||
$this->updateTicketCounts();
|
||||
}
|
||||
|
||||
public function updateTicketCounts()
|
||||
public function updateTicketCounts(): void
|
||||
{
|
||||
$this->open = $this->tickets->filter(function ($ticket) {
|
||||
return in_array($ticket->status, ['open', 'pending']);
|
||||
})->count();
|
||||
$this->open = $this->tickets->filter(fn($ticket): bool => in_array($ticket->status, ['open', 'pending']))->count();
|
||||
|
||||
$this->closed = $this->tickets->filter(function ($ticket) {
|
||||
return $ticket->status === 'closed';
|
||||
})->count();
|
||||
$this->closed = $this->tickets->filter(fn($ticket): bool => $ticket->status === 'closed')->count();
|
||||
}
|
||||
|
||||
protected function getClientIp()
|
||||
|
||||
Reference in New Issue
Block a user