chore: code refactor via rector
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Livewire\Dashboard;
|
||||
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Livewire\Component;
|
||||
use Session;
|
||||
|
||||
class Bulk extends Component
|
||||
{
|
||||
@@ -11,15 +11,13 @@ class Bulk extends Component
|
||||
|
||||
public $bulkCount = 1;
|
||||
|
||||
private $isSubscribed = false;
|
||||
|
||||
public function mount()
|
||||
public function mount(): void
|
||||
{
|
||||
$subscriptionCheck = auth()->user()->subscribedToProduct(config('app.plans')[0]['product_id']);
|
||||
Session::put('isSubscribed', $subscriptionCheck);
|
||||
}
|
||||
|
||||
public function generateBulk()
|
||||
public function generateBulk(): void
|
||||
{
|
||||
$this->validate([
|
||||
'bulkCount' => 'required|integer|min:1|max:500',
|
||||
@@ -44,7 +42,7 @@ class Bulk extends Component
|
||||
$filename = 'bulk_emails_'.now()->format('Ymd_His').'.txt';
|
||||
$content = implode(PHP_EOL, $this->bulkEmails);
|
||||
|
||||
return response()->streamDownload(function () use ($content) {
|
||||
return response()->streamDownload(function () use ($content): void {
|
||||
echo $content;
|
||||
}, $filename);
|
||||
}
|
||||
@@ -54,11 +52,11 @@ class Bulk extends Component
|
||||
$domain = $this->getRandomDomain();
|
||||
if ($domain == 'gmail.com' || $domain == 'googlemail.com') {
|
||||
$uname = $this->getRandomGmailUser();
|
||||
$uname_len = strlen($uname);
|
||||
$uname_len = strlen((string) $uname);
|
||||
$len_power = $uname_len - 1;
|
||||
$combination = pow(2, $len_power);
|
||||
$combination = 2 ** $len_power;
|
||||
$rand_comb = mt_rand(1, $combination);
|
||||
$formatted = implode(' ', str_split($uname));
|
||||
$formatted = implode(' ', str_split((string) $uname));
|
||||
$uname_exp = explode(' ', $formatted);
|
||||
|
||||
$bin = intval('');
|
||||
@@ -70,7 +68,7 @@ class Bulk extends Component
|
||||
$email = '';
|
||||
for ($i = 0; $i < $len_power; $i++) {
|
||||
$email .= $uname_exp[$i];
|
||||
if ($bin[$i]) {
|
||||
if ($bin[$i] !== '' && $bin[$i] !== '0') {
|
||||
$email .= '.';
|
||||
}
|
||||
}
|
||||
@@ -83,15 +81,14 @@ class Bulk extends Component
|
||||
}
|
||||
|
||||
return $email;
|
||||
} else {
|
||||
return $this->generateRandomUsername().'@'.$domain;
|
||||
}
|
||||
return $this->generateRandomUsername().'@'.$domain;
|
||||
}
|
||||
|
||||
private function generateRandomUsername(): string
|
||||
{
|
||||
$start = json_decode(config('app.settings.configuration_settings'))->random_username_length_min ?? 0;
|
||||
$end = json_decode(config('app.settings.configuration_settings'))->random_username_length_max ?? 0;
|
||||
$start = json_decode((string) config('app.settings.configuration_settings'))->random_username_length_min ?? 0;
|
||||
$end = json_decode((string) config('app.settings.configuration_settings'))->random_username_length_max ?? 0;
|
||||
if ($start == 0 && $end == 0) {
|
||||
return $this->generatePronounceableWord();
|
||||
}
|
||||
@@ -101,25 +98,25 @@ class Bulk extends Component
|
||||
|
||||
private function generatedRandomBetweenLength($start, $end): string
|
||||
{
|
||||
$length = rand($start, $end);
|
||||
$length = random_int($start, $end);
|
||||
|
||||
return $this->generateRandomString($length);
|
||||
}
|
||||
|
||||
private function getRandomDomain()
|
||||
{
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$domains = json_decode((string) config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$count = count($domains);
|
||||
|
||||
return $count > 0 ? $domains[rand(1, $count) - 1] : '';
|
||||
return $count > 0 ? $domains[random_int(1, $count) - 1] : '';
|
||||
}
|
||||
|
||||
private function getRandomGmailUser()
|
||||
{
|
||||
$gmailusername = json_decode(config('app.settings.configuration_settings'))->premium_gmailUsernames ?? [];
|
||||
$gmailusername = json_decode((string) config('app.settings.configuration_settings'))->premium_gmailUsernames ?? [];
|
||||
$count = count($gmailusername);
|
||||
|
||||
return $count > 0 ? $gmailusername[rand(1, $count) - 1] : '';
|
||||
return $count > 0 ? $gmailusername[random_int(1, $count) - 1] : '';
|
||||
}
|
||||
|
||||
private function generatePronounceableWord(): string
|
||||
@@ -129,21 +126,21 @@ class Bulk extends Component
|
||||
$a = $c.$v; // both
|
||||
$random = '';
|
||||
for ($j = 0; $j < 2; $j++) {
|
||||
$random .= $c[rand(0, strlen($c) - 1)];
|
||||
$random .= $v[rand(0, strlen($v) - 1)];
|
||||
$random .= $a[rand(0, strlen($a) - 1)];
|
||||
$random .= $c[random_int(0, strlen($c) - 1)];
|
||||
$random .= $v[random_int(0, strlen($v) - 1)];
|
||||
$random .= $a[random_int(0, strlen($a) - 1)];
|
||||
}
|
||||
|
||||
return $random;
|
||||
}
|
||||
|
||||
private function generateRandomString($length = 10): string
|
||||
private function generateRandomString(int $length = 10): string
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
$randomString .= $characters[random_int(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
return $randomString;
|
||||
@@ -153,8 +150,7 @@ class Bulk extends Component
|
||||
{
|
||||
if (Session::get('isSubscribed')) {
|
||||
return view('livewire.dashboard.bulk')->layout('components.layouts.dashboard');
|
||||
} else {
|
||||
return view('livewire.dashboard.not-subscribed')->layout('components.layouts.dashboard');
|
||||
}
|
||||
return view('livewire.dashboard.not-subscribed')->layout('components.layouts.dashboard');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user