Skip to content

Commit 80b3b65

Browse files
authored
Improves property promotion docs (#8546)
1 parent 198e665 commit 80b3b65

13 files changed

+44
-63
lines changed

blade.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -768,10 +768,9 @@ Component constructor arguments should be specified using `camelCase`, while `ke
768768
/**
769769
* Create the component instance.
770770
*/
771-
public function __construct(string $alertType)
772-
{
773-
$this->alertType = $alertType;
774-
}
771+
public function __construct(
772+
public string $alertType,
773+
) {}
775774

776775
The `$alertType` argument may be provided to the component like so:
777776

@@ -868,12 +867,11 @@ use App\Services\AlertCreator;
868867
/**
869868
* Create the component instance.
870869
*/
871-
public function __construct(AlertCreator $creator, string $type, string $message)
872-
{
873-
$this->creator = $creator;
874-
$this->type = $type;
875-
$this->message = $message;
876-
}
870+
public function __construct(
871+
public AlertCreator $creator,
872+
public string $type,
873+
public string $message,
874+
) {}
877875
```
878876

879877
<a name="hiding-attributes-and-methods"></a>
@@ -889,19 +887,19 @@ If you would like to prevent some public methods or properties from being expose
889887

890888
class Alert extends Component
891889
{
892-
/**
893-
* The alert type.
894-
*
895-
* @var string
896-
*/
897-
public $type;
898-
899890
/**
900891
* The properties / methods that should not be exposed to the component template.
901892
*
902893
* @var array
903894
*/
904895
protected $except = ['type'];
896+
897+
/**
898+
* Create the component instance.
899+
*/
900+
public function __construct(
901+
public string $type,
902+
) {}
905903
}
906904

907905
<a name="component-attributes"></a>

cashier-paddle.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,11 +1232,8 @@ Alternatively, you can perform more precise customization by [listening](/docs/{
12321232
{
12331233
/**
12341234
* Handle received Paddle webhooks.
1235-
*
1236-
* @param \Laravel\Paddle\Events\WebhookReceived $event
1237-
* @return void
12381235
*/
1239-
public function handle(WebhookReceived $event)
1236+
public function handle(WebhookReceived $event): void
12401237
{
12411238
if ($event->payload['alert_name'] === 'subscription_payment_failed') {
12421239
// Handle the failed subscription payment...

collections.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,10 +1347,9 @@ The `mapInto()` method iterates over the collection, creating a new instance of
13471347
/**
13481348
* Create a new currency instance.
13491349
*/
1350-
function __construct(string $code)
1351-
{
1352-
$this->code = $code;
1353-
}
1350+
function __construct(
1351+
public string $code
1352+
) {}
13541353
}
13551354

13561355
$collection = collect(['USD', 'EUR', 'GBP']);
@@ -1934,7 +1933,7 @@ The `reduceSpread` method reduces the collection to an array of values, passing
19341933

19351934
[$creditsRemaining, $batch] = Image::where('status', 'unprocessed')
19361935
->get()
1937-
->reduceSpread(function ($creditsRemaining, $batch, $image) {
1936+
->reduceSpread(function (int $creditsRemaining, Collection $batch, Image $image) {
19381937
if ($creditsRemaining >= $image->creditsRequired()) {
19391938
$batch->push($image);
19401939

container.md

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,9 @@ This statement tells the container that it should inject the `RedisEventPusher`
184184
/**
185185
* Create a new class instance.
186186
*/
187-
public function __construct(EventPusher $pusher)
188-
{
189-
$this->pusher = $pusher;
190-
}
187+
public function __construct(
188+
protected EventPusher $pusher
189+
) {}
191190

192191
<a name="contextual-binding"></a>
193192
### Contextual Binding
@@ -247,13 +246,6 @@ Occasionally, you may have a class that receives an array of typed objects using
247246

248247
class Firewall
249248
{
250-
/**
251-
* The logger instance.
252-
*
253-
* @var \App\Services\Logger
254-
*/
255-
protected $logger;
256-
257249
/**
258250
* The filter instances.
259251
*
@@ -264,9 +256,10 @@ Occasionally, you may have a class that receives an array of typed objects using
264256
/**
265257
* Create a new class instance.
266258
*/
267-
public function __construct(Logger $logger, Filter ...$filters)
268-
{
269-
$this->logger = $logger;
259+
public function __construct(
260+
protected Logger $logger,
261+
Filter ...$filters,
262+
) {
270263
$this->filters = $filters;
271264
}
272265
}
@@ -366,10 +359,9 @@ If you would like to have the Laravel container instance itself injected into a
366359
/**
367360
* Create a new class instance.
368361
*/
369-
public function __construct(Container $container)
370-
{
371-
$this->container = $container;
372-
}
362+
public function __construct(
363+
protected Container $container
364+
) {}
373365

374366
<a name="automatic-injection"></a>
375367
### Automatic Injection

helpers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ You may also sort the array by the results of a given closure:
928928
['name' => 'Chair'],
929929
];
930930

931-
$sorted = array_values(Arr::sortDesc($array, function ($value) {
931+
$sorted = array_values(Arr::sortDesc($array, function (array $value) {
932932
return $value['name'];
933933
}));
934934

@@ -4072,8 +4072,8 @@ The `value` function returns the value it is given. However, if you pass a closu
40724072

40734073
Additional arguments may be passed to the `value` function. If the first argument is a closure then the additional parameters will be passed to the closure as arguments, otherwise they will be ignored:
40744074

4075-
$result = value(function ($name) {
4076-
return $parameter;
4075+
$result = value(function (string $name) {
4076+
return $name;
40774077
}, 'Taylor');
40784078

40794079
// 'Taylor'

horizon.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Horizon exposes a dashboard at the `/horizon` URI. By default, you will only be
143143
<a name="alternative-authentication-strategies"></a>
144144
#### Alternative Authentication Strategies
145145

146-
Remember that Laravel automatically injects the authenticated user into the gate closure. If your application is providing Horizon security via another method, such as IP restrictions, then your Horizon users may not need to "login". Therefore, you will need to change `function ($user)` closure signature above to `function ($user = null)` in order to force Laravel to not require authentication.
146+
Remember that Laravel automatically injects the authenticated user into the gate closure. If your application is providing Horizon security via another method, such as IP restrictions, then your Horizon users may not need to "login". Therefore, you will need to change `function (User $user)` closure signature above to `function (User $user = null)` in order to force Laravel to not require authentication.
147147

148148
<a name="silenced-jobs"></a>
149149
### Silenced Jobs

http-tests.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ Assert that the session contains the given piece of data:
10561056

10571057
If needed, a closure can be provided as the second argument to the `assertSessionHas` method. The assertion will pass if the closure returns `true`:
10581058

1059-
$response->assertSessionHas($key, function ($value) {
1059+
$response->assertSessionHas($key, function (User $value) {
10601060
return $value->name === 'Taylor Otwell';
10611061
});
10621062

@@ -1069,7 +1069,7 @@ Assert that the session has a given value in the [flashed input array](/docs/{{v
10691069

10701070
If needed, a closure can be provided as the second argument to the `assertSessionHasInput` method. The assertion will pass if the closure returns `true`:
10711071

1072-
$response->assertSessionHasInput($key, function ($value) {
1072+
$response->assertSessionHasInput($key, function (string $value) {
10731073
return Crypt::decryptString($value) === 'secret';
10741074
});
10751075

localization.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,8 @@ In these cases, Laravel allows you to register a custom formatting handler for t
192192

193193
/**
194194
* Bootstrap any application services.
195-
*
196-
* @return void
197195
*/
198-
public function boot()
196+
public function boot(): void
199197
{
200198
Lang::stringable(function (Money $money) {
201199
return $money->formatTo('en_GB');

mail.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ Laravel includes a variety of mail transports; however, you may wish to write yo
10391039
use MailchimpTransactional\ApiClient;
10401040
use Symfony\Component\Mailer\SentMessage;
10411041
use Symfony\Component\Mailer\Transport\AbstractTransport;
1042+
use Symfony\Component\Mime\Address;
10421043
use Symfony\Component\Mime\MessageConverter;
10431044

10441045
class MailchimpTransport extends AbstractTransport
@@ -1061,7 +1062,7 @@ Laravel includes a variety of mail transports; however, you may wish to write yo
10611062

10621063
$this->client->messages->send(['message' => [
10631064
'from_email' => $email->getFrom(),
1064-
'to' => collect($email->getTo())->map(function ($email) {
1065+
'to' => collect($email->getTo())->map(function (Address $email) {
10651066
return ['email' => $email->getAddress(), 'type' => 'to'];
10661067
})->all(),
10671068
'subject' => $email->getSubject(),

notifications.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ Or, if you would like to specify a specific queue connection that should be used
209209
/**
210210
* Determine which connections should be used for each notification channel.
211211
*
212-
* @return array
212+
* @return array<string, string>
213213
*/
214-
public function viaConnections()
214+
public function viaConnections(): array
215215
{
216216
return [
217217
'mail' => 'redis',

0 commit comments

Comments
 (0)