Skip to content

Commit

Permalink
fix: resolved linting errors, test failures and static analysis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislarsen committed Jul 4, 2024
1 parent 271d48d commit 2703df4
Show file tree
Hide file tree
Showing 16 changed files with 479 additions and 439 deletions.
19 changes: 11 additions & 8 deletions app/Models/BackupTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Traits\HasTags;
use Cron\CronExpression;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand Down Expand Up @@ -66,10 +67,10 @@ public static function logsCountPerMonthForLastSixMonths(int $userId): array
->get();

return $results->mapWithKeys(function ($item) use ($locale) {
$carbonDate = Carbon::parse($item->month_date)->locale($locale);
$carbonDate = Carbon::parse($item->getAttribute('month_date'))->locale($locale);
$localizedMonth = ucfirst($carbonDate->isoFormat('MMM YYYY'));

return [$localizedMonth => $item->count];
return [$localizedMonth => $item->getAttribute('count')];
})->toArray();
}

Expand All @@ -80,16 +81,18 @@ public static function logsCountPerMonthForLastSixMonths(int $userId): array
*/
public static function backupTasksCountByType(int $userId): array
{
return self::query()
/** @var Collection<int, Model> $results */
$results = self::query()
->where('user_id', $userId)
->selectRaw('type, COUNT(*) as count')
->groupBy('type')
->get()
->mapWithKeys(function ($item) {
$localizedType = __($item->type);
->get();

return $results->mapWithKeys(function ($item) {
$localizedType = __($item->getAttribute('type'));

return [$localizedType => $item->count];
})
return [$localizedType => $item->getAttribute('count')];
})
->toArray();
}

Expand Down
14 changes: 7 additions & 7 deletions app/Services/Backup/Tasks/AbstractBackupTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public function handle(): void
}
}

public function generateBackupFileName(string $extension): string
{
$prefix = $this->backupTask->hasFileNameAppended() ? $this->backupTask->appended_file_name . '_' : '';

return "{$prefix}backup_{$this->backupTask->id}_" . date('YmdHis') . ".{$extension}";
}

abstract protected function performBackup(): void;

/**
Expand Down Expand Up @@ -114,11 +121,4 @@ protected function logMessage(string $message): void
{
$this->logWithTimestamp($message, $this->backupTask->user->timezone);
}

protected function generateBackupFileName(string $extension): string
{
$prefix = $this->backupTask->hasFileNameAppended() ? $this->backupTask->appended_file_name . '_' : '';

return "{$prefix}backup_{$this->backupTask->id}_" . date('YmdHis') . ".{$extension}";
}
}
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
'en' => 'English (English)',
'da' => 'Danish (Dansk)',
'zh' => 'Chinese (中文)',
'ru' => 'Russian (Русский)'
'ru' => 'Russian (Русский)',
],
];
4 changes: 2 additions & 2 deletions resources/views/livewire/backup-tasks/index-table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
</div>
<script>
document.addEventListener('livewire:navigated', function () {
let filesType = @json(__('Files Task'), JSON_THROW_ON_ERROR);
let databaseType = @json(__('Database Task'), JSON_THROW_ON_ERROR);
let filesType = {!! __('Files Task') !!};
let databaseType = {!! __('Database Task') !!};
tippy('#files-type', {
content: filesType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
});

test('the authorized user can delete a task log', function () {
\Masmerise\Toaster\Toaster::fake();
Toaster::fake();

$user = User::factory()->create();
$task = BackupTask::factory()->create(['user_id' => $user->id]);
Expand Down
Loading

0 comments on commit 2703df4

Please sign in to comment.