diff --git a/src/App/Console/Commands/SetupDevEnvironment.php b/src/App/Console/Commands/SetupDevEnvironment.php index 0f12effa..4f8b54f9 100644 --- a/src/App/Console/Commands/SetupDevEnvironment.php +++ b/src/App/Console/Commands/SetupDevEnvironment.php @@ -1,5 +1,4 @@ setUpFaker(); } @@ -761,7 +759,7 @@ class SetupDevEnvironment extends Command collect([$members[0]->id, $members[1]->id]) ->each( - fn($id) => DB::table('team_folder_members') + fn ($id) => DB::table('team_folder_members') ->insert([ 'parent_id' => $companyProjectFolder->id, 'user_id' => $id, @@ -771,7 +769,7 @@ class SetupDevEnvironment extends Command collect([$members[2]->id, $members[3]->id]) ->each( - fn($id) => DB::table('team_folder_members') + fn ($id) => DB::table('team_folder_members') ->insert([ 'parent_id' => $financeDocumentsFolder->id, 'user_id' => $id, @@ -782,7 +780,7 @@ class SetupDevEnvironment extends Command // Create invitations collect([$members[4], $members[5]]) ->each( - fn($user) => TeamFolderInvitation::factory() + fn ($user) => TeamFolderInvitation::factory() ->create([ 'email' => $user->email, 'parent_id' => $companyProjectFolder->id, @@ -1080,7 +1078,6 @@ class SetupDevEnvironment extends Command }); } - /** * Generate demo traffic data */ @@ -1089,17 +1086,17 @@ class SetupDevEnvironment extends Command $user = User::all(); foreach (range(0, 45) as $day) { - $user - ->each(fn($user) => DB::table('traffic') - ->insert([ - 'id' => Str::uuid(), - 'user_id' => $user->id, - 'upload' => random_int(1111111, 9999999), - 'download' => random_int(11111111, 99999999), - 'created_at' => now()->subDays($day), - 'updated_at' => now()->subDays($day), - ]) + ->each( + fn ($user) => DB::table('traffic') + ->insert([ + 'id' => Str::uuid(), + 'user_id' => $user->id, + 'upload' => random_int(1111111, 9999999), + 'download' => random_int(11111111, 99999999), + 'created_at' => now()->subDays($day), + 'updated_at' => now()->subDays($day), + ]) ); } } @@ -1184,7 +1181,7 @@ class SetupDevEnvironment extends Command // Create thumbnail only if image is larger than predefined image sizes if ($intervention->getWidth() > $size['size']) { // Generate thumbnail - $intervention->resize($size['size'], null, fn($constraint) => $constraint->aspectRatio())->stream(); + $intervention->resize($size['size'], null, fn ($constraint) => $constraint->aspectRatio())->stream(); // Store thumbnail to disk Storage::put("files/$user->id/{$size['name']}-{$file_name}", $intervention); diff --git a/src/App/Users/Models/User.php b/src/App/Users/Models/User.php index 75a202a7..856859a2 100644 --- a/src/App/Users/Models/User.php +++ b/src/App/Users/Models/User.php @@ -1,15 +1,14 @@ $this->usedCapacity, 'used_formatted' => Metric::bytes($this->usedCapacity)->format(), @@ -103,7 +102,7 @@ class User extends Authenticatable implements MustVerifyEmail } return [ - 'used' => (float)get_storage_fill_percentage($this->usedCapacity, $this->limitations->max_storage_amount), + 'used' => (float) get_storage_fill_percentage($this->usedCapacity, $this->limitations->max_storage_amount), 'used_formatted' => get_storage_fill_percentage($this->usedCapacity, $this->limitations->max_storage_amount) . '%', 'capacity' => $this->limitations->max_storage_amount, 'capacity_formatted' => format_gigabytes($this->limitations->max_storage_amount), diff --git a/src/App/Users/Models/UserLimitation.php b/src/App/Users/Models/UserLimitation.php index 509150e0..cc700024 100644 --- a/src/App/Users/Models/UserLimitation.php +++ b/src/App/Users/Models/UserLimitation.php @@ -1,13 +1,12 @@ $totalUsedEmails->count(), 'total' => (int) $this->max_team_members, 'percentage' => ($totalUsedEmails->count() / $this->max_team_members) * 100, - 'meta' => [ + 'meta' => [ 'allowed_emails' => $totalUsedEmails, ], ]; diff --git a/src/App/Users/Resources/UserResource.php b/src/App/Users/Resources/UserResource.php index c67b4b28..9bbd0db4 100644 --- a/src/App/Users/Resources/UserResource.php +++ b/src/App/Users/Resources/UserResource.php @@ -1,5 +1,4 @@ $this->limitations, ], ], - $this->mergeWhen($this->hasSubscription(), fn() => [ + $this->mergeWhen($this->hasSubscription(), fn () => [ 'subscription' => new SubscriptionResource($this->subscription), ]), ], diff --git a/src/App/Users/Resources/UserStorageResource.php b/src/App/Users/Resources/UserStorageResource.php index cd9a4715..fd26011b 100644 --- a/src/App/Users/Resources/UserStorageResource.php +++ b/src/App/Users/Resources/UserStorageResource.php @@ -1,5 +1,4 @@ [ - 'id' => (string)$this->id, + 'id' => (string) $this->id, 'type' => 'storage', 'attributes' => [ 'used' => Metric::bytes($this->usedCapacity)->format(), 'capacity' => format_gigabytes($this->limitations->max_storage_amount), - 'percentage' => (float)get_storage_fill_percentage($this->usedCapacity, $this->limitations->max_storage_amount), + 'percentage' => (float) get_storage_fill_percentage($this->usedCapacity, $this->limitations->max_storage_amount), ], 'meta' => [ 'traffic' => [ @@ -40,23 +39,23 @@ class UserStorageResource extends JsonResource ], 'images' => [ 'used' => Metric::bytes($images)->format(), - 'percentage' => (float)get_storage_fill_percentage($images, $this->limitations->max_storage_amount), + 'percentage' => (float) get_storage_fill_percentage($images, $this->limitations->max_storage_amount), ], 'audios' => [ 'used' => Metric::bytes($audios)->format(), - 'percentage' => (float)get_storage_fill_percentage($audios, $this->limitations->max_storage_amount), + 'percentage' => (float) get_storage_fill_percentage($audios, $this->limitations->max_storage_amount), ], 'videos' => [ 'used' => Metric::bytes($videos)->format(), - 'percentage' => (float)get_storage_fill_percentage($videos, $this->limitations->max_storage_amount), + 'percentage' => (float) get_storage_fill_percentage($videos, $this->limitations->max_storage_amount), ], 'documents' => [ 'used' => Metric::bytes($documents)->format(), - 'percentage' => (float)get_storage_fill_percentage($documents, $this->limitations->max_storage_amount), + 'percentage' => (float) get_storage_fill_percentage($documents, $this->limitations->max_storage_amount), ], 'others' => [ 'used' => Metric::bytes($others)->format(), - 'percentage' => (float)get_storage_fill_percentage($others, $this->limitations->max_storage_amount), + 'percentage' => (float) get_storage_fill_percentage($others, $this->limitations->max_storage_amount), ], ], ], @@ -127,8 +126,8 @@ class UserStorageResource extends JsonResource ->where('created_at', '>', $period) ->sum('upload'); - $upload = $trafficRecords->map(fn($record) => round(($record->upload / $uploadMax) * 100, 2)); - $download = $trafficRecords->map(fn($record) => round(($record->download / $downloadMax) * 100, 2)); + $upload = $trafficRecords->map(fn ($record) => round(($record->upload / $uploadMax) * 100, 2)); + $download = $trafficRecords->map(fn ($record) => round(($record->download / $downloadMax) * 100, 2)); return [$downloadTotal, $uploadTotal, $upload, $download]; } diff --git a/src/Domain/Admin/Actions/DeleteUserDataAction.php b/src/Domain/Admin/Actions/DeleteUserDataAction.php index 18631350..31df5807 100644 --- a/src/Domain/Admin/Actions/DeleteUserDataAction.php +++ b/src/Domain/Admin/Actions/DeleteUserDataAction.php @@ -14,7 +14,6 @@ class DeleteUserDataAction { // Delete user avatar if exists if ($user->settings->getRawOriginal('avatar')) { - // TODO: delete all generated avatars Storage::delete($user->settings->getRawOriginal('avatar')); } diff --git a/src/Domain/Admin/Controllers/Dashboard/GetWidgetsValuesController.php b/src/Domain/Admin/Controllers/Dashboard/GetWidgetsValuesController.php index aad4484a..b1b73880 100644 --- a/src/Domain/Admin/Controllers/Dashboard/GetWidgetsValuesController.php +++ b/src/Domain/Admin/Controllers/Dashboard/GetWidgetsValuesController.php @@ -16,10 +16,10 @@ class GetWidgetsValuesController extends Controller )->format(); return [ - 'license' => get_settings('license'), - 'app_version' => config('vuefilemanager.version'), - 'total_users' => User::count(), - 'total_used_space' => $storage_usage, + 'license' => get_settings('license'), + 'app_version' => config('vuefilemanager.version'), + 'total_users' => User::count(), + 'total_used_space' => $storage_usage, 'total_premium_users' => Subscription::count(), ]; } diff --git a/src/Domain/SetupWizard/Controllers/StorePlansController.php b/src/Domain/SetupWizard/Controllers/StorePlansController.php index 15894f42..49b3da66 100644 --- a/src/Domain/SetupWizard/Controllers/StorePlansController.php +++ b/src/Domain/SetupWizard/Controllers/StorePlansController.php @@ -10,7 +10,6 @@ use Domain\SetupWizard\Requests\StoreStripePlansRequest; */ class StorePlansController extends Controller { - public function __invoke( StoreStripePlansRequest $request ): Response { diff --git a/src/Domain/Teams/Actions/CheckMaxTeamMembersLimitAction.php b/src/Domain/Teams/Actions/CheckMaxTeamMembersLimitAction.php index 260a1a3b..3c75ea5c 100644 --- a/src/Domain/Teams/Actions/CheckMaxTeamMembersLimitAction.php +++ b/src/Domain/Teams/Actions/CheckMaxTeamMembersLimitAction.php @@ -1,5 +1,4 @@ firstOrCreate([ 'user_id' => $user_id, ]); diff --git a/src/Domain/Traffic/Actions/RecordUploadAction.php b/src/Domain/Traffic/Actions/RecordUploadAction.php index 85f7b447..6bc8a2a4 100644 --- a/src/Domain/Traffic/Actions/RecordUploadAction.php +++ b/src/Domain/Traffic/Actions/RecordUploadAction.php @@ -12,7 +12,7 @@ class RecordUploadAction int $file_size, string $user_id, ): void { - $record = Traffic::currentMonth() + $record = Traffic::currentDay() ->firstOrCreate([ 'user_id' => $user_id, ]); diff --git a/src/Domain/Traffic/Models/Traffic.php b/src/Domain/Traffic/Models/Traffic.php index fca98201..de3e59da 100644 --- a/src/Domain/Traffic/Models/Traffic.php +++ b/src/Domain/Traffic/Models/Traffic.php @@ -7,8 +7,6 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; /** - * @method static whereYear(string $string, string $string1, int $year) - * @method static currentMonth() * @property string id * @property string user_id * @property int upload @@ -18,29 +16,21 @@ class Traffic extends Model { use HasFactory; - protected $fillable = [ - 'user_id', - 'upload', - 'download', - ]; + protected $guarded = []; public $incrementing = false; protected $keyType = 'string'; - public function scopeCurrentMonth($query): Builder + public function scopeCurrentDay($query): Builder { - return $query - ->whereYear('created_at', '=', now()->year) - ->whereMonth('created_at', '=', now()->month); + return $query->whereDate('created_at', today()); } protected static function boot() { parent::boot(); - static::creating(function ($model) { - $model->id = (string) Str::uuid(); - }); + static::creating(fn ($model) => $model->id = (string) Str::uuid()); } } diff --git a/src/Support/helpers.php b/src/Support/helpers.php index 2e986383..0f2eeae3 100644 --- a/src/Support/helpers.php +++ b/src/Support/helpers.php @@ -485,7 +485,7 @@ if (! function_exists('user_storage_percentage')) { /** * Get user capacity fill by percentage */ - function user_storage_percentage($id, int $additionals = null) + function user_storage_percentage($id, ?int $additionals = null) { $user = User::findOrFail($id); diff --git a/tests/App/Users/UserAccountTest.php b/tests/App/Users/UserAccountTest.php index 4e935885..7d0fe641 100644 --- a/tests/App/Users/UserAccountTest.php +++ b/tests/App/Users/UserAccountTest.php @@ -1,5 +1,4 @@ each( - fn($size) => Storage::disk('local') + fn ($size) => Storage::disk('local') ->assertExists("avatars/{$size['name']}-{$user->settings->getRawOriginal('avatar')}") ); } @@ -137,7 +136,7 @@ class UserAccountTest extends TestCase ->assertStatus(200) ->assertExactJson([ 'data' => [ - 'id' => (string)$user->id, + 'id' => (string) $user->id, 'type' => 'user', 'attributes' => [ 'avatar' => null, @@ -157,7 +156,7 @@ class UserAccountTest extends TestCase 'relationships' => [ 'settings' => [ 'data' => [ - 'id' => (string)$user->id, + 'id' => (string) $user->id, 'type' => 'settings', 'attributes' => [ 'avatar' => $user->settings->avatar, diff --git a/tests/Domain/Teams/TeamLimitsTest.php b/tests/Domain/Teams/TeamLimitsTest.php index 785448eb..a0977878 100644 --- a/tests/Domain/Teams/TeamLimitsTest.php +++ b/tests/Domain/Teams/TeamLimitsTest.php @@ -1,5 +1,4 @@ count(5) ->create(); - $members->each(fn($member) => TeamFolderMember::factory() + $members->each( + fn ($member) => TeamFolderMember::factory() ->create([ 'parent_id' => $user->folders[0]->id, 'user_id' => $member->id, @@ -84,4 +84,4 @@ class TeamLimitsTest extends TestCase ]) ->assertCreated(); } -} \ No newline at end of file +} diff --git a/tests/Domain/Traffic/TrafficTest.php b/tests/Domain/Traffic/TrafficTest.php index 1c62f5ac..7cf00fca 100644 --- a/tests/Domain/Traffic/TrafficTest.php +++ b/tests/Domain/Traffic/TrafficTest.php @@ -1,7 +1,6 @@ actingAs($this->user) @@ -67,7 +67,7 @@ class TrafficTest extends TestCase 'created_at' => now(), ]); - $this->travel(1)->months(); + $this->travel(1)->day(); $secondFile = UploadedFile::fake() ->image('fake-file-2.jpg', 1200); @@ -200,8 +200,8 @@ class TrafficTest extends TestCase DB::table('traffic')->insert([ 'id' => Str::uuid(), 'user_id' => $user->id, - 'upload' => random_int(11111111, 99999999), - 'download' => random_int(11111111, 99999999), + 'upload' => 10000 * $day, + 'download' => 1000000 * $day, 'created_at' => now()->subDays($day), 'updated_at' => now()->subDays($day), ]); @@ -209,6 +209,10 @@ class TrafficTest extends TestCase $this->actingAs($user) ->get('/api/user/storage') - ->assertOk(); + ->assertOk() + ->assertJsonFragment([ + 'download' => '465.00MB', + 'upload' => '4.65MB', + ]); } }