chore: code refactor via rector
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use App\ColorPicker;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -48,7 +48,7 @@ class PremiumEmail extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public static function createEmail($message, $email): void
|
||||
public static function createEmail(array $message, $email): void
|
||||
{
|
||||
$initialData = $message;
|
||||
if (config('app.fetch_from_db') && config('app.fetch_from_remote_db')) {
|
||||
@@ -56,9 +56,9 @@ class PremiumEmail extends Model
|
||||
} else {
|
||||
$utcTime = CarbonImmutable::instance($message['timestamp'])->setTimezone('UTC')->toDateTimeString();
|
||||
}
|
||||
$messageId = Carbon::parse($utcTime)->format('Ymd').$initialData['id'];
|
||||
$messageId = Date::parse($utcTime)->format('Ymd').$initialData['id'];
|
||||
$userId = \auth()->user()->id;
|
||||
$exists = PremiumEmail::where('user_id', $userId)->where('message_id', $messageId)->exists();
|
||||
$exists = PremiumEmail::query()->where('user_id', $userId)->where('message_id', $messageId)->exists();
|
||||
|
||||
$data = [
|
||||
'user_id' => $userId,
|
||||
@@ -82,7 +82,7 @@ class PremiumEmail extends Model
|
||||
];
|
||||
|
||||
if (! $exists) {
|
||||
PremiumEmail::create($data);
|
||||
PremiumEmail::query()->create($data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,14 +90,14 @@ class PremiumEmail extends Model
|
||||
{
|
||||
|
||||
$validator = Validator::make(['user_id' => $userId], [
|
||||
'user_id' => 'required|integer',
|
||||
'user_id' => ['required', 'integer'],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::whereJsonContains('user_id', $userId)->orderBy('timestamp', 'desc')->get();
|
||||
return self::query()->whereJsonContains('user_id', $userId)->orderBy('timestamp', 'desc')->get();
|
||||
}
|
||||
|
||||
public static function parseEmail($userId, $deleted = []): array
|
||||
@@ -114,7 +114,7 @@ class PremiumEmail extends Model
|
||||
|
||||
if (in_array($message['message_id'], $deleted)) {
|
||||
// If it exists, delete the matching record from the 'emails' table
|
||||
Email::where('message_id', $message['message_id'])->delete();
|
||||
Email::query()->where('message_id', $message['message_id'])->delete();
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ class PremiumEmail extends Model
|
||||
$blocked = false;
|
||||
|
||||
$timestamp = $message['timestamp'];
|
||||
$carbonTimestamp = Carbon::parse($timestamp, 'UTC');
|
||||
$carbonTimestamp = Date::parse($timestamp, 'UTC');
|
||||
$obj = [];
|
||||
$obj['subject'] = $message['subject'];
|
||||
$obj['to'] = $message['to'];
|
||||
@@ -130,16 +130,16 @@ class PremiumEmail extends Model
|
||||
$obj['sender_email'] = $message['from_email'];
|
||||
$obj['timestamp'] = $message['timestamp'];
|
||||
$obj['date'] = $carbonTimestamp->format('d M Y h:i A');
|
||||
$obj['datediff'] = $carbonTimestamp->diffForHumans(Carbon::now('UTC'));
|
||||
$obj['datediff'] = $carbonTimestamp->diffForHumans(Date::now('UTC'));
|
||||
$obj['id'] = $message['message_id'];
|
||||
$obj['content'] = $message['body_html'];
|
||||
$obj['contentText'] = $message['body_text'];
|
||||
$obj['attachments'] = [];
|
||||
$obj['is_seen'] = $message['is_seen'];
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr($message['from_name'] ?: $message['from_email'], 0, 1)));
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr((string) $message['from_name'] ?: (string) $message['from_email'], 0, 1)));
|
||||
|
||||
$domain = explode('@', $obj['sender_email'])[1];
|
||||
$blocked = in_array($domain, json_decode(config('app.settings.configuration_settings'))->blocked_domains);
|
||||
$domain = explode('@', (string) $obj['sender_email'])[1];
|
||||
$blocked = in_array($domain, json_decode((string) config('app.settings.configuration_settings'))->blocked_domains);
|
||||
if ($blocked) {
|
||||
$obj['subject'] = __('Blocked');
|
||||
$obj['content'] = __('Emails from').' '.$domain.' '.__('are blocked by Admin');
|
||||
@@ -162,7 +162,7 @@ class PremiumEmail extends Model
|
||||
file_put_contents(storage_path('logs/zemail.csv'), request()->ip().','.date('Y-m-d h:i:s a').','.$obj['sender_email'].','.$email.PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
PremiumEmail::where('message_id', $message['message_id'])->update(['is_seen' => true]);
|
||||
PremiumEmail::query()->where('message_id', $message['message_id'])->update(['is_seen' => true]);
|
||||
if (++$count > $limit) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user