php cs fixer tweak

This commit is contained in:
Peter Papp
2021-07-23 10:50:29 +02:00
parent d190eeb46d
commit 8951ebc69f
15 changed files with 70 additions and 105 deletions

1
.gitignore vendored
View File

@@ -10,6 +10,7 @@
.env .env
.env.backup .env.backup
.env.testing .env.testing
.php-cs-fixer.cache
.phpunit.result.cache .phpunit.result.cache
.phpstorm.meta.php .phpstorm.meta.php
.vscode/ .vscode/

File diff suppressed because one or more lines are too long

View File

@@ -16,6 +16,9 @@ $config = new PhpCsFixer\Config();
return $config->setRules([ return $config->setRules([
'@PSR2' => true, '@PSR2' => true,
'nullable_type_declaration_for_default_null_value' => [
'use_nullable_type_declaration' => true
],
'array_syntax' => [ 'array_syntax' => [
'syntax' => 'short' 'syntax' => 'short'
], ],
@@ -35,6 +38,7 @@ return $config->setRules([
'cast_spaces' => [ 'cast_spaces' => [
'space' => 'single' 'space' => 'single'
], ],
'use_arrow_functions' => true,
'phpdoc_single_line_var_spacing' => true, 'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true, 'phpdoc_var_without_name' => true,
'single_space_after_construct' => true, 'single_space_after_construct' => true,
@@ -71,5 +75,6 @@ return $config->setRules([
'constant_case' => true, 'constant_case' => true,
'lowercase_keywords' => true, 'lowercase_keywords' => true,
'lowercase_static_reference' => true, 'lowercase_static_reference' => true,
'lambda_not_used_import' => true,
]) ])
->setFinder($finder); ->setFinder($finder);

View File

@@ -11,6 +11,4 @@
| |
*/ */
Broadcast::channel('App.User.{id}', function ($user, $id) { Broadcast::channel('App.User.{id}', fn ($user, $id) => (int) $user->id === (int) $id);
return (int) $user->id === (int) $id;
});

View File

@@ -25,8 +25,6 @@ class AuthServiceProvider extends ServiceProvider
$this->registerPolicies(); $this->registerPolicies();
// Define admin maintenance gate // Define admin maintenance gate
Gate::define('maintenance', function ($user) { Gate::define('maintenance', fn ($user) => $user->role === 'admin');
return $user->role === 'admin';
});
} }
} }

View File

@@ -32,12 +32,8 @@ class FortifyServiceProvider extends ServiceProvider
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class); Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class); Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
RateLimiter::for('login', function (Request $request) { RateLimiter::for('login', fn (Request $request) => Limit::perMinute(20)->by($request->email.$request->ip()));
return Limit::perMinute(20)->by($request->email.$request->ip());
});
RateLimiter::for('two-factor', function (Request $request) { RateLimiter::for('two-factor', fn (Request $request) => Limit::perMinute(5)->by($request->session()->get('login.id')));
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
} }
} }

View File

@@ -114,9 +114,7 @@ class User extends Authenticatable implements MustVerifyEmail
public function getUsedCapacityAttribute(): int public function getUsedCapacityAttribute(): int
{ {
return $this->filesWithTrashed return $this->filesWithTrashed
->map(function ($item) { ->map(fn ($item) => $item->getRawOriginal())->sum('filesize');
return $item->getRawOriginal();
})->sum('filesize');
} }
/** /**

View File

@@ -21,35 +21,25 @@ class UserStorageResource extends JsonResource
// Get all images // Get all images
$images = File::where('user_id', $this->id) $images = File::where('user_id', $this->id)
->where('type', 'image')->get()->map(function ($item) { ->where('type', 'image')->get()->map(fn ($item) => (int) $item->getRawOriginal('filesize'))->sum();
return (int) $item->getRawOriginal('filesize');
})->sum();
// Get all audios // Get all audios
$audios = File::where('user_id', $this->id) $audios = File::where('user_id', $this->id)
->where('type', 'audio')->get()->map(function ($item) { ->where('type', 'audio')->get()->map(fn ($item) => (int) $item->getRawOriginal('filesize'))->sum();
return (int) $item->getRawOriginal('filesize');
})->sum();
// Get all videos // Get all videos
$videos = File::where('user_id', $this->id) $videos = File::where('user_id', $this->id)
->where('type', 'video')->get()->map(function ($item) { ->where('type', 'video')->get()->map(fn ($item) => (int) $item->getRawOriginal('filesize'))->sum();
return (int) $item->getRawOriginal('filesize');
})->sum();
// Get all documents // Get all documents
$documents = File::where('user_id', $this->id) $documents = File::where('user_id', $this->id)
->whereIn('mimetype', $document_mimetypes)->get()->map(function ($item) { ->whereIn('mimetype', $document_mimetypes)->get()->map(fn ($item) => (int) $item->getRawOriginal('filesize'))->sum();
return (int) $item->getRawOriginal('filesize');
})->sum();
// Get all other files // Get all other files
$others = File::where('user_id', $this->id) $others = File::where('user_id', $this->id)
->whereNotIn('mimetype', $document_mimetypes) ->whereNotIn('mimetype', $document_mimetypes)
->whereNotIn('type', ['audio', 'video', 'image']) ->whereNotIn('type', ['audio', 'video', 'image'])
->get()->map(function ($item) { ->get()->map(fn ($item) => (int) $item->getRawOriginal('filesize'))->sum();
return (int) $item->getRawOriginal('filesize');
})->sum();
return [ return [
'data' => [ 'data' => [

View File

@@ -48,14 +48,10 @@ class PaymentMethodsController extends Controller
// filter payment methods without default payment // filter payment methods without default payment
$paymentMethodsMapped = Cache::rememberForever($slug_payment_methods, function () use ($defaultPaymentMethod, $user) { $paymentMethodsMapped = Cache::rememberForever($slug_payment_methods, function () use ($defaultPaymentMethod, $user) {
$paymentMethods = $user->paymentMethods()->filter(function ($paymentMethod) use ($defaultPaymentMethod) { $paymentMethods = $user->paymentMethods()->filter(fn ($paymentMethod) => $paymentMethod->id !== $defaultPaymentMethod->id);
return $paymentMethod->id !== $defaultPaymentMethod->id;
});
// Get payment methods // Get payment methods
return $paymentMethods->map(function ($paymentMethod) { return $paymentMethods->map(fn ($paymentMethod) => $paymentMethod->asStripePaymentMethod())->values()->all();
return $paymentMethod->asStripePaymentMethod();
})->values()->all();
}); });
} }

View File

@@ -13,9 +13,7 @@ class ActivePlansController
public function __invoke(): PricingCollection public function __invoke(): PricingCollection
{ {
// Get pricing from cache // Get pricing from cache
$pricing = Cache::rememberForever('pricing', function () { $pricing = Cache::rememberForever('pricing', fn () => resolve(StripeService::class)->getActivePlans());
return resolve(StripeService::class)->getActivePlans();
});
// Format pricing to collection // Format pricing to collection
$collection = new PricingCollection($pricing); $collection = new PricingCollection($pricing);

View File

@@ -22,9 +22,7 @@ class PlansController extends Controller
{ {
// Store or Get plans to cache // Store or Get plans to cache
$plans = cache() $plans = cache()
->rememberForever('plans', function () { ->rememberForever('plans', fn () => $this->stripe->getPlans());
return $this->stripe->getPlans();
});
return response(new PlanCollection($plans), 200); return response(new PlanCollection($plans), 200);
} }
@@ -36,9 +34,7 @@ class PlansController extends Controller
{ {
// Store or Get plan to cache // Store or Get plan to cache
$plan = cache() $plan = cache()
->rememberForever("plan-$id", function () use ($id) { ->rememberForever("plan-$id", fn () => $this->stripe->getPlan($id));
return $this->stripe->getPlan($id);
});
return response(new PlanResource($plan), 200); return response(new PlanResource($plan), 200);
} }
@@ -51,9 +47,7 @@ class PlansController extends Controller
{ {
if (is_demo()) { if (is_demo()) {
$plan = cache() $plan = cache()
->rememberForever('plan-starter-pack', function () { ->rememberForever('plan-starter-pack', fn () => $this->stripe->getPlan('starter-pack'));
return $this->stripe->getPlan('starter-pack');
});
return new PlanResource($plan); return new PlanResource($plan);
} }

View File

@@ -21,9 +21,7 @@ class StripeWebhookController extends CashierController
public function handleCustomerSubscriptionDeleted($payload) public function handleCustomerSubscriptionDeleted($payload)
{ {
if ($user = $this->getUserByStripeId($payload['data']['object']['customer'])) { if ($user = $this->getUserByStripeId($payload['data']['object']['customer'])) {
$user->subscriptions->filter(function ($subscription) use ($payload) { $user->subscriptions->filter(fn ($subscription) => $subscription->stripe_id === $payload['data']['object']['id'])->each(function ($subscription) {
return $subscription->stripe_id === $payload['data']['object']['id'];
})->each(function ($subscription) {
$subscription->markAsCancelled(); $subscription->markAsCancelled();
}); });
} }

View File

@@ -17,9 +17,7 @@ trait Subscription
); );
// Find tax rate // Find tax rate
$user_tax_rate = $rates->first(function ($item) { $user_tax_rate = $rates->first(fn ($item) => $item['country'] === $this->settings->country && $item['active']);
return $item['country'] === $this->settings->country && $item['active'];
});
return $user_tax_rate ? [$user_tax_rate['id']] : []; return $user_tax_rate ? [$user_tax_rate['id']] : [];
} }

View File

@@ -596,9 +596,7 @@ if (! function_exists('map_language_translations')) {
*/ */
function map_language_translations($translations): Collection function map_language_translations($translations): Collection
{ {
return $translations->map(function ($string) { return $translations->map(fn ($string) => [$string->key => $string->value])->collapse();
return [$string->key => $string->value];
})->collapse();
} }
} }
@@ -904,9 +902,7 @@ if (! function_exists('get_files_for_zip')) {
// Get all children folders and folders within // Get all children folders and folders within
if ($folders->folders->isNotEmpty()) { if ($folders->folders->isNotEmpty()) {
$folders->folders->map(function ($folder) use ($files, $path) { $folders->folders->map(fn ($folder) => get_files_for_zip($folder, $files, $path));
return get_files_for_zip($folder, $files, $path);
});
} }
return get_files_for_zip($folders->folders->first(), $files, $path); return get_files_for_zip($folders->folders->first(), $files, $path);

View File

@@ -430,7 +430,7 @@ class BrowseTest extends TestCase
}); });
collect([$folder, $file]) collect([$folder, $file])
->each(function ($item) use ($user) { ->each(function ($item) {
$this->getJson('/api/browse/share') $this->getJson('/api/browse/share')
->assertStatus(200) ->assertStatus(200)
->assertJsonFragment([ ->assertJsonFragment([