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

@@ -15,61 +15,66 @@ $finder = PhpCsFixer\Finder::create()
$config = new PhpCsFixer\Config(); $config = new PhpCsFixer\Config();
return $config->setRules([ return $config->setRules([
'@PSR2' => true, '@PSR2' => true,
'array_syntax' => [ 'nullable_type_declaration_for_default_null_value' => [
'use_nullable_type_declaration' => true
],
'array_syntax' => [
'syntax' => 'short' 'syntax' => 'short'
], ],
'ordered_imports' => [ 'ordered_imports' => [
'sort_algorithm' => 'length' 'sort_algorithm' => 'length'
], ],
'blank_line_before_statement' => [ 'blank_line_before_statement' => [
'statements' => ['break', 'case', 'continue', 'declare', 'default', 'do', 'exit', 'for', 'foreach', 'goto', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', 'yield_from'], 'statements' => ['break', 'case', 'continue', 'declare', 'default', 'do', 'exit', 'for', 'foreach', 'goto', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', 'yield_from'],
], ],
'method_argument_space' => [ 'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline', 'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true, 'keep_multiple_spaces_after_comma' => true,
], ],
'no_extra_blank_lines' => [ 'no_extra_blank_lines' => [
'tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait'], 'tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait'],
], ],
'cast_spaces' => [ 'cast_spaces' => [
'space' => 'single' 'space' => 'single'
], ],
'phpdoc_single_line_var_spacing' => true, 'use_arrow_functions' => true,
'phpdoc_var_without_name' => true, 'phpdoc_single_line_var_spacing' => true,
'single_space_after_construct' => true, 'phpdoc_var_without_name' => true,
'single_line_after_imports' => true, 'single_space_after_construct' => true,
'no_unused_imports' => true, 'single_line_after_imports' => true,
'not_operator_with_successor_space' => true, 'no_unused_imports' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']], 'not_operator_with_successor_space' => true,
'phpdoc_scalar' => true, 'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'unary_operator_spaces' => true, 'phpdoc_scalar' => true,
'binary_operator_spaces' => ['operators' => ['=>' => 'align']], 'unary_operator_spaces' => true,
'single_trait_insert_per_statement' => false, 'binary_operator_spaces' => ['operators' => ['=>' => 'align']],
'method_chaining_indentation' => true, 'single_trait_insert_per_statement' => false,
'array_indentation' => true, 'method_chaining_indentation' => true,
'single_quote' => true, 'array_indentation' => true,
'no_singleline_whitespace_before_semicolons' => true, 'single_quote' => true,
'no_empty_statement' => true, 'no_singleline_whitespace_before_semicolons' => true,
'standardize_increment' => true, 'no_empty_statement' => true,
'object_operator_without_whitespace' => true, 'standardize_increment' => true,
'ternary_operator_spaces' => true, 'object_operator_without_whitespace' => true,
'no_leading_namespace_whitespace' => true, 'ternary_operator_spaces' => true,
'no_blank_lines_before_namespace' => true, 'no_leading_namespace_whitespace' => true,
'blank_line_after_namespace' => true, 'no_blank_lines_before_namespace' => true,
'fully_qualified_strict_types' => true, 'blank_line_after_namespace' => true,
'single_line_throw' => true, 'fully_qualified_strict_types' => true,
'function_typehint_space' => true, 'single_line_throw' => true,
'simplified_if_return' => true, 'function_typehint_space' => true,
'no_useless_else' => true, 'simplified_if_return' => true,
'no_unneeded_curly_braces' => true, 'no_useless_else' => true,
'no_empty_comment' => true, 'no_unneeded_curly_braces' => true,
'no_blank_lines_after_class_opening' => true, 'no_empty_comment' => true,
'whitespace_after_comma_in_array' => true, 'no_blank_lines_after_class_opening' => true,
'trim_array_spaces' => true, 'whitespace_after_comma_in_array' => true,
'no_whitespace_before_comma_in_array' => true, 'trim_array_spaces' => true,
'constant_case' => true, 'no_whitespace_before_comma_in_array' => true,
'lowercase_keywords' => true, 'constant_case' => true,
'lowercase_static_reference' => true, 'lowercase_keywords' => 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([