Skip to content

Commit 5ccbe7d

Browse files
committed
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 laravel#10166
1 parent b6423cc commit 5ccbe7d

9 files changed

+40
-40
lines changed

authorization.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ So far, we have only examined gates that return simple boolean values. However,
168168

169169
Gate::define('edit-settings', function (User $user) {
170170
return $user->isAdmin
171-
? Response::allow()
172-
: Response::deny('You must be an administrator.');
171+
? Response::allow()
172+
: Response::deny('You must be an administrator.');
173173
});
174174

175175
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,
199199

200200
Gate::define('edit-settings', function (User $user) {
201201
return $user->isAdmin
202-
? Response::allow()
203-
: Response::denyWithStatus(404);
202+
? Response::allow()
203+
: Response::denyWithStatus(404);
204204
});
205205

206206
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
211211

212212
Gate::define('edit-settings', function (User $user) {
213213
return $user->isAdmin
214-
? Response::allow()
215-
: Response::denyAsNotFound();
214+
? Response::allow()
215+
: Response::denyAsNotFound();
216216
});
217217

218218
<a name="intercepting-gate-checks"></a>
@@ -362,8 +362,8 @@ So far, we have only examined policy methods that return simple boolean values.
362362
public function update(User $user, Post $post): Response
363363
{
364364
return $user->id === $post->user_id
365-
? Response::allow()
366-
: Response::deny('You do not own this post.');
365+
? Response::allow()
366+
: Response::deny('You do not own this post.');
367367
}
368368

369369
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;
399399
public function update(User $user, Post $post): Response
400400
{
401401
return $user->id === $post->user_id
402-
? Response::allow()
403-
: Response::denyWithStatus(404);
402+
? Response::allow()
403+
: Response::denyWithStatus(404);
404404
}
405405

406406
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
415415
public function update(User $user, Post $post): Response
416416
{
417417
return $user->id === $post->user_id
418-
? Response::allow()
419-
: Response::denyAsNotFound();
418+
? Response::allow()
419+
: Response::denyAsNotFound();
420420
}
421421

422422
<a name="methods-without-models"></a>

eloquent-mutators.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ A classic example of an inbound only cast is a "hashing" cast. For example, we m
727727
public function set(Model $model, string $key, mixed $value, array $attributes): string
728728
{
729729
return is_null($this->algorithm)
730-
? bcrypt($value)
731-
: hash($this->algorithm, $value);
730+
? bcrypt($value)
731+
: hash($this->algorithm, $value);
732732
}
733733
}
734734

notifications.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ If you are sending an [on-demand notification](#on-demand-notifications), the `$
681681
public function toMail(object $notifiable): Mailable
682682
{
683683
$address = $notifiable instanceof AnonymousNotifiable
684-
? $notifiable->routeNotificationFor('mail')
685-
: $notifiable->email;
684+
? $notifiable->routeNotificationFor('mail')
685+
: $notifiable->email;
686686

687687
return (new InvoicePaidMailable($this->invoice))
688688
->to($address);

passwords.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ Next, we will define a route that handles the form submission request from the "
7474
);
7575

7676
return $status === Password::ResetLinkSent
77-
? back()->with(['status' => __($status)])
78-
: back()->withErrors(['email' => __($status)]);
77+
? back()->with(['status' => __($status)])
78+
: back()->withErrors(['email' => __($status)]);
7979
})->middleware('guest')->name('password.email');
8080

8181
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
137137
);
138138

139139
return $status === Password::PasswordReset
140-
? redirect()->route('login')->with('status', __($status))
141-
: back()->withErrors(['email' => [__($status)]]);
140+
? redirect()->route('login')->with('status', __($status))
141+
: back()->withErrors(['email' => [__($status)]]);
142142
})->middleware('guest')->name('password.update');
143143

144144
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.

pennant.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ class PodcastController
199199
public function index(Request $request): Response
200200
{
201201
return Feature::active('new-api')
202-
? $this->resolveNewApiResponse($request)
203-
: $this->resolveLegacyApiResponse($request);
202+
? $this->resolveNewApiResponse($request)
203+
: $this->resolveLegacyApiResponse($request);
204204
}
205205

206206
// ...
@@ -211,8 +211,8 @@ Although features are checked against the currently authenticated user by defaul
211211

212212
```php
213213
return Feature::for($user)->active('new-api')
214-
? $this->resolveNewApiResponse($request)
215-
: $this->resolveLegacyApiResponse($request);
214+
? $this->resolveNewApiResponse($request)
215+
: $this->resolveLegacyApiResponse($request);
216216
```
217217

218218
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
260260
public function index(Request $request): Response
261261
{
262262
return Feature::active(NewApi::class)
263-
? $this->resolveNewApiResponse($request)
264-
: $this->resolveLegacyApiResponse($request);
263+
? $this->resolveNewApiResponse($request)
264+
: $this->resolveLegacyApiResponse($request);
265265
}
266266

267267
// ...
@@ -509,8 +509,8 @@ As discussed, features are typically checked against the currently authenticated
509509

510510
```php
511511
return Feature::for($user)->active('new-api')
512-
? $this->resolveNewApiResponse($request)
513-
: $this->resolveLegacyApiResponse($request);
512+
? $this->resolveNewApiResponse($request)
513+
: $this->resolveLegacyApiResponse($request);
514514
```
515515

516516
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:

queues.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ For example, you may wish to allow users to backup their data once per hour whil
464464
{
465465
RateLimiter::for('backups', function (object $job) {
466466
return $job->user->vipCustomer()
467-
? Limit::none()
468-
: Limit::perHour(1)->by($job->user->id);
467+
? Limit::none()
468+
: Limit::perHour(1)->by($job->user->id);
469469
});
470470
}
471471

routing.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,8 @@ Since rate limiter callbacks receive the incoming HTTP request instance, you may
791791

792792
RateLimiter::for('uploads', function (Request $request) {
793793
return $request->user()->vipCustomer()
794-
? Limit::none()
795-
: Limit::perMinute(100);
794+
? Limit::none()
795+
: Limit::perMinute(100);
796796
});
797797

798798
<a name="segmenting-rate-limits"></a>
@@ -802,16 +802,16 @@ Sometimes you may wish to segment rate limits by some arbitrary value. For examp
802802

803803
RateLimiter::for('uploads', function (Request $request) {
804804
return $request->user()->vipCustomer()
805-
? Limit::none()
806-
: Limit::perMinute(100)->by($request->ip());
805+
? Limit::none()
806+
: Limit::perMinute(100)->by($request->ip());
807807
});
808808

809809
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:
810810

811811
RateLimiter::for('uploads', function (Request $request) {
812812
return $request->user()
813-
? Limit::perMinute(100)->by($request->user()->id)
814-
: Limit::perMinute(10)->by($request->ip());
813+
? Limit::perMinute(100)->by($request->user()->id)
814+
: Limit::perMinute(10)->by($request->ip());
815815
});
816816

817817
<a name="multiple-rate-limits"></a>

telescope.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ Telescope allows you to search entries by "tag". Often, tags are Eloquent model
246246

247247
Telescope::tag(function (IncomingEntry $entry) {
248248
return $entry->type === 'request'
249-
? ['status:'.$entry->content['response_status']]
250-
: [];
249+
? ['status:'.$entry->content['response_status']]
250+
: [];
251251
});
252252
}
253253

validation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2389,8 +2389,8 @@ public function boot(): void
23892389
$rule = Password::min(8);
23902390

23912391
return $this->app->isProduction()
2392-
? $rule->mixedCase()->uncompromised()
2393-
: $rule;
2392+
? $rule->mixedCase()->uncompromised()
2393+
: $rule;
23942394
});
23952395
}
23962396
```

0 commit comments

Comments
 (0)