chore: code refactor via rector

This commit is contained in:
idevakk
2025-11-14 02:01:01 -08:00
parent 90ab79b3a2
commit ae795880ed
148 changed files with 1520 additions and 1486 deletions

View File

@@ -2,9 +2,13 @@
namespace App\Livewire\Frontend;
use Illuminate\Routing\Redirector;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Date;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use App\Models\Log;
use App\Models\ZEmail;
use Carbon\Carbon;
use Livewire\Component;
class Action extends Component
@@ -23,9 +27,9 @@ class Action extends Component
public $initial;
public function mount()
public function mount(): void
{
$this->domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
$this->domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? [];
$this->email = ZEmail::getEmail();
$this->emails = ZEmail::getEmails();
$this->validateDomainInEmail();
@@ -37,17 +41,17 @@ class Action extends Component
return $this->showAlert('error', __('Please enter Username'));
}
$this->checkDomainInUsername();
if (strlen($this->username) < json_decode(config('app.settings.configuration_settings'))->custom_username_length_min || strlen($this->username) > json_decode(config('app.settings.configuration_settings'))->custom_username_length_max) {
return $this->showAlert('error', __('Username length cannot be less than').' '.json_decode(config('app.settings.configuration_settings'))->custom_username_length_min.' '.__('and greater than').' '.json_decode(config('app.settings.configuration_settings'))->custom_username_length_max);
if (strlen((string) $this->username) < json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_min || strlen((string) $this->username) > json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_max) {
return $this->showAlert('error', __('Username length cannot be less than').' '.json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_min.' '.__('and greater than').' '.json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_max);
}
if (! $this->domain) {
return $this->showAlert('error', __('Please Select a Domain'));
}
if (in_array($this->username, json_decode(config('app.settings.configuration_settings'))->forbidden_ids)) {
if (in_array($this->username, json_decode((string) config('app.settings.configuration_settings'))->forbidden_ids)) {
return $this->showAlert('error', __('Username not allowed'));
}
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of MAX ').json_decode(config('app.settings.configuration_settings'))->email_limit.__(' temp mail'));
return $this->showAlert('error', __('You have reached daily limit of MAX ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail'));
}
if (! $this->checkUsedEmail()) {
return $this->showAlert('error', __('Sorry! That email is already been used by someone else. Please try a different email address.'));
@@ -55,49 +59,49 @@ class Action extends Component
$this->email = ZEmail::createCustomEmail($this->username, $this->domain);
return redirect()->route('mailbox');
return to_route('mailbox');
}
public function random()
{
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode(config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
}
$this->email = ZEmail::generateRandomEmail();
return redirect()->route('mailbox');
return to_route('mailbox');
}
public function gmail()
{
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode(config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
}
$this->email = ZEmail::generateRandomGmail();
return redirect()->route('mailbox');
return to_route('mailbox');
}
public function outlook()
{
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode(config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
}
$this->email = ZEmail::generateRandomOutlook();
return redirect()->route('mailbox');
return to_route('mailbox');
}
public function deleteEmail()
public function deleteEmail(): Redirector|RedirectResponse
{
return redirect()->route('delete', ['email' => $this->email]);
return to_route('delete', ['email' => $this->email]);
}
private function showAlert($type, $message): void
private function showAlert(string $type, $message): void
{
$check = json_decode(config('app.settings.configuration_settings'))->email_limit;
if (strpos($message, $check) !== false) {
$check = json_decode((string) config('app.settings.configuration_settings'))->email_limit;
if (str_contains((string) $message, (string) $check)) {
$this->dispatch('promotePremium');
}
$this->dispatch('showAlert', ['type' => $type, 'message' => $message]);
@@ -105,31 +109,23 @@ class Action extends Component
private function checkEmailLimit(): bool
{
$logs = Log::select('ip', 'email')->where('ip', request()->ip())->where('created_at', '>', Carbon::now()->subDay())->groupBy('email')->groupBy('ip')->get();
if (count($logs) >= json_decode(config('app.settings.configuration_settings'))->email_limit) {
return false;
}
return true;
$logs = Log::query()->select('ip', 'email')->where('ip', request()->ip())->where('created_at', '>', Date::now()->subDay())->groupBy('email')->groupBy('ip')->get();
return count($logs) < json_decode((string) config('app.settings.configuration_settings'))->email_limit;
}
private function checkUsedEmail(): bool
{
if (json_decode(config('app.settings.configuration_settings'))->disable_used_email) {
$check = Log::where('email', $this->user.'@'.$this->domain)->where('ip', '<>', request()->ip())->count();
if ($check > 0) {
return false;
}
return true;
if (json_decode((string) config('app.settings.configuration_settings'))->disable_used_email) {
$check = Log::query()->where('email', $this->user.'@'.$this->domain)->where('ip', '<>', request()->ip())->count();
return $check <= 0;
}
return true;
}
private function checkDomainInUsername()
private function checkDomainInUsername(): void
{
$parts = explode('@', $this->username);
$parts = explode('@', (string) $this->username);
if (isset($parts[1])) {
if (in_array($parts[1], $this->domains)) {
$this->domain = $parts[1];
@@ -140,23 +136,23 @@ class Action extends Component
private function validateDomainInEmail(): void
{
$data = explode('@', $this->email);
$data = explode('@', (string) $this->email);
if (isset($data[1])) {
$domain = $data[1];
$domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
$domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? [];
if (! in_array($domain, $domains)) {
$key = array_search($this->email, $this->emails);
ZEmail::removeEmail($this->email);
if ($key == 0 && count($this->emails) == 1 && json_decode(config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
redirect()->route('home');
if ($key == 0 && count($this->emails) === 1 && json_decode((string) config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
to_route('home');
} else {
redirect()->route('mailbox');
to_route('mailbox');
}
}
}
}
public function render()
public function render(): Factory|View
{
return view('livewire.frontend.action');
}