From 5ccbe7d99f1b7ead121dcd972b26c147a0e50d6d Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 14 Feb 2025 11:19:30 -0600 Subject: [PATCH] standardize multiline ternary alignment use a single indent for multiline ternary statements. this is better than alignment with an arbitrary pattern in the first line because it doesn't need to be shifted as adjustments are made to the code. along with #10166 --- authorization.md | 24 ++++++++++++------------ eloquent-mutators.md | 4 ++-- notifications.md | 4 ++-- passwords.md | 8 ++++---- pennant.md | 16 ++++++++-------- queues.md | 4 ++-- routing.md | 12 ++++++------ telescope.md | 4 ++-- validation.md | 4 ++-- 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/authorization.md b/authorization.md index ec79b888e2f..0a30ae87af3 100644 --- a/authorization.md +++ b/authorization.md @@ -168,8 +168,8 @@ So far, we have only examined gates that return simple boolean values. However, Gate::define('edit-settings', function (User $user) { return $user->isAdmin - ? Response::allow() - : Response::deny('You must be an administrator.'); + ? Response::allow() + : Response::deny('You must be an administrator.'); }); Even when you return an authorization response from your gate, the `Gate::allows` method will still return a simple boolean value; however, you may use the `Gate::inspect` method to get the full authorization response returned by the gate: @@ -199,8 +199,8 @@ When an action is denied via a Gate, a `403` HTTP response is returned; however, Gate::define('edit-settings', function (User $user) { return $user->isAdmin - ? Response::allow() - : Response::denyWithStatus(404); + ? Response::allow() + : Response::denyWithStatus(404); }); Because hiding resources via a `404` response is such a common pattern for web applications, the `denyAsNotFound` method is offered for convenience: @@ -211,8 +211,8 @@ Because hiding resources via a `404` response is such a common pattern for web a Gate::define('edit-settings', function (User $user) { return $user->isAdmin - ? Response::allow() - : Response::denyAsNotFound(); + ? Response::allow() + : Response::denyAsNotFound(); }); @@ -362,8 +362,8 @@ So far, we have only examined policy methods that return simple boolean values. public function update(User $user, Post $post): Response { return $user->id === $post->user_id - ? Response::allow() - : Response::deny('You do not own this post.'); + ? Response::allow() + : Response::deny('You do not own this post.'); } When returning an authorization response from your policy, the `Gate::allows` method will still return a simple boolean value; however, you may use the `Gate::inspect` method to get the full authorization response returned by the gate: @@ -399,8 +399,8 @@ When an action is denied via a policy method, a `403` HTTP response is returned; public function update(User $user, Post $post): Response { return $user->id === $post->user_id - ? Response::allow() - : Response::denyWithStatus(404); + ? Response::allow() + : Response::denyWithStatus(404); } Because hiding resources via a `404` response is such a common pattern for web applications, the `denyAsNotFound` method is offered for convenience: @@ -415,8 +415,8 @@ Because hiding resources via a `404` response is such a common pattern for web a public function update(User $user, Post $post): Response { return $user->id === $post->user_id - ? Response::allow() - : Response::denyAsNotFound(); + ? Response::allow() + : Response::denyAsNotFound(); } diff --git a/eloquent-mutators.md b/eloquent-mutators.md index 34a5ba2e7a6..cf4a4c012f3 100644 --- a/eloquent-mutators.md +++ b/eloquent-mutators.md @@ -727,8 +727,8 @@ A classic example of an inbound only cast is a "hashing" cast. For example, we m public function set(Model $model, string $key, mixed $value, array $attributes): string { return is_null($this->algorithm) - ? bcrypt($value) - : hash($this->algorithm, $value); + ? bcrypt($value) + : hash($this->algorithm, $value); } } diff --git a/notifications.md b/notifications.md index 17235144293..aeea2809029 100644 --- a/notifications.md +++ b/notifications.md @@ -681,8 +681,8 @@ If you are sending an [on-demand notification](#on-demand-notifications), the `$ public function toMail(object $notifiable): Mailable { $address = $notifiable instanceof AnonymousNotifiable - ? $notifiable->routeNotificationFor('mail') - : $notifiable->email; + ? $notifiable->routeNotificationFor('mail') + : $notifiable->email; return (new InvoicePaidMailable($this->invoice)) ->to($address); diff --git a/passwords.md b/passwords.md index 658c6ef5e46..21a5833e329 100644 --- a/passwords.md +++ b/passwords.md @@ -74,8 +74,8 @@ Next, we will define a route that handles the form submission request from the " ); return $status === Password::ResetLinkSent - ? back()->with(['status' => __($status)]) - : back()->withErrors(['email' => __($status)]); + ? back()->with(['status' => __($status)]) + : back()->withErrors(['email' => __($status)]); })->middleware('guest')->name('password.email'); Before moving on, let's examine this route in more detail. First, the request's `email` attribute is validated. Next, we will use Laravel's built-in "password broker" (via the `Password` facade) to send a password reset link to the user. The password broker will take care of retrieving the user by the given field (in this case, the email address) and sending the user a password reset link via Laravel's built-in [notification system](/docs/{{version}}/notifications). @@ -137,8 +137,8 @@ Of course, we need to define a route to actually handle the password reset form ); return $status === Password::PasswordReset - ? redirect()->route('login')->with('status', __($status)) - : back()->withErrors(['email' => [__($status)]]); + ? redirect()->route('login')->with('status', __($status)) + : back()->withErrors(['email' => [__($status)]]); })->middleware('guest')->name('password.update'); Before moving on, let's examine this route in more detail. First, the request's `token`, `email`, and `password` attributes are validated. Next, we will use Laravel's built-in "password broker" (via the `Password` facade) to validate the password reset request credentials. diff --git a/pennant.md b/pennant.md index c6ab436696f..885f46148d8 100644 --- a/pennant.md +++ b/pennant.md @@ -199,8 +199,8 @@ class PodcastController public function index(Request $request): Response { return Feature::active('new-api') - ? $this->resolveNewApiResponse($request) - : $this->resolveLegacyApiResponse($request); + ? $this->resolveNewApiResponse($request) + : $this->resolveLegacyApiResponse($request); } // ... @@ -211,8 +211,8 @@ Although features are checked against the currently authenticated user by defaul ```php return Feature::for($user)->active('new-api') - ? $this->resolveNewApiResponse($request) - : $this->resolveLegacyApiResponse($request); + ? $this->resolveNewApiResponse($request) + : $this->resolveLegacyApiResponse($request); ``` Pennant also offers some additional convenience methods that may prove useful when determining if a feature is active or not: @@ -260,8 +260,8 @@ class PodcastController public function index(Request $request): Response { return Feature::active(NewApi::class) - ? $this->resolveNewApiResponse($request) - : $this->resolveLegacyApiResponse($request); + ? $this->resolveNewApiResponse($request) + : $this->resolveLegacyApiResponse($request); } // ... @@ -509,8 +509,8 @@ As discussed, features are typically checked against the currently authenticated ```php return Feature::for($user)->active('new-api') - ? $this->resolveNewApiResponse($request) - : $this->resolveLegacyApiResponse($request); + ? $this->resolveNewApiResponse($request) + : $this->resolveLegacyApiResponse($request); ``` Of course, feature scopes are not limited to "users". Imagine you have built a new billing experience that you are rolling out to entire teams rather than individual users. Perhaps you would like the oldest teams to have a slower rollout than the newer teams. Your feature resolution closure might look something like the following: diff --git a/queues.md b/queues.md index 96b52b43b33..e1a54c79db0 100644 --- a/queues.md +++ b/queues.md @@ -464,8 +464,8 @@ For example, you may wish to allow users to backup their data once per hour whil { RateLimiter::for('backups', function (object $job) { return $job->user->vipCustomer() - ? Limit::none() - : Limit::perHour(1)->by($job->user->id); + ? Limit::none() + : Limit::perHour(1)->by($job->user->id); }); } diff --git a/routing.md b/routing.md index 790e7fd1d72..14ca74b0302 100644 --- a/routing.md +++ b/routing.md @@ -791,8 +791,8 @@ Since rate limiter callbacks receive the incoming HTTP request instance, you may RateLimiter::for('uploads', function (Request $request) { return $request->user()->vipCustomer() - ? Limit::none() - : Limit::perMinute(100); + ? Limit::none() + : Limit::perMinute(100); }); @@ -802,16 +802,16 @@ Sometimes you may wish to segment rate limits by some arbitrary value. For examp RateLimiter::for('uploads', function (Request $request) { return $request->user()->vipCustomer() - ? Limit::none() - : Limit::perMinute(100)->by($request->ip()); + ? Limit::none() + : Limit::perMinute(100)->by($request->ip()); }); To illustrate this feature using another example, we can limit access to the route to 100 times per minute per authenticated user ID or 10 times per minute per IP address for guests: RateLimiter::for('uploads', function (Request $request) { return $request->user() - ? Limit::perMinute(100)->by($request->user()->id) - : Limit::perMinute(10)->by($request->ip()); + ? Limit::perMinute(100)->by($request->user()->id) + : Limit::perMinute(10)->by($request->ip()); }); diff --git a/telescope.md b/telescope.md index 6e3e24f3b6d..b008e5a1d48 100644 --- a/telescope.md +++ b/telescope.md @@ -246,8 +246,8 @@ Telescope allows you to search entries by "tag". Often, tags are Eloquent model Telescope::tag(function (IncomingEntry $entry) { return $entry->type === 'request' - ? ['status:'.$entry->content['response_status']] - : []; + ? ['status:'.$entry->content['response_status']] + : []; }); } diff --git a/validation.md b/validation.md index fd2d1df26ed..6184e05a488 100644 --- a/validation.md +++ b/validation.md @@ -2389,8 +2389,8 @@ public function boot(): void $rule = Password::min(8); return $this->app->isProduction() - ? $rule->mixedCase()->uncompromised() - : $rule; + ? $rule->mixedCase()->uncompromised() + : $rule; }); } ```