Skip to content

Commit

Permalink
[11.x] use promoted properties (#53807)
Browse files Browse the repository at this point in the history
* use promoted properties

this commit uses promoted properties to remove a lot of boilerplate code.

I avoided promoting any `public` properties that lacked type-hints, but had type-hints in the constructor signature. while unlikely to cause issues, this technically is a change in behavior, and should be handled against the `master` branch.

I **did** upgrade `protected` properties that lacked type hints to the type hint provided in the constructor signature. This should be okay because even though the properties themselves weren't type-hinted, the only way to update them was through a type-hinted constructor.

some styling decisions made in this PR:

- ALWAYS use multiline constructors, with each parameter on a new line
- use a trailing comma in multiline constructors
- leave in constructor docblocks for now. could/should be removed eventually

* style fix

* fix styling
  • Loading branch information
browner12 authored Dec 10, 2024
1 parent bbd2273 commit 69b19ce
Show file tree
Hide file tree
Showing 50 changed files with 175 additions and 702 deletions.
40 changes: 6 additions & 34 deletions src/Illuminate/Auth/Access/Events/GateEvaluated.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,6 @@

class GateEvaluated
{
/**
* The authenticatable model.
*
* @var \Illuminate\Contracts\Auth\Authenticatable|null
*/
public $user;

/**
* The ability being evaluated.
*
* @var string
*/
public $ability;

/**
* The result of the evaluation.
*
* @var bool|null
*/
public $result;

/**
* The arguments given during evaluation.
*
* @var array
*/
public $arguments;

/**
* Create a new event instance.
*
Expand All @@ -41,11 +13,11 @@ class GateEvaluated
* @param array $arguments
* @return void
*/
public function __construct($user, $ability, $result, $arguments)
{
$this->user = $user;
$this->ability = $ability;
$this->result = $result;
$this->arguments = $arguments;
public function __construct(
public $user,
public $ability,
public $result,
public $arguments,
) {
}
}
31 changes: 5 additions & 26 deletions src/Illuminate/Auth/DatabaseUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@

class DatabaseUserProvider implements UserProvider
{
/**
* The active database connection.
*
* @var \Illuminate\Database\ConnectionInterface
*/
protected $connection;

/**
* The hasher implementation.
*
* @var \Illuminate\Contracts\Hashing\Hasher
*/
protected $hasher;

/**
* The table containing the users.
*
* @var string
*/
protected $table;

/**
* Create a new database user provider.
*
Expand All @@ -40,11 +19,11 @@ class DatabaseUserProvider implements UserProvider
* @param string $table
* @return void
*/
public function __construct(ConnectionInterface $connection, HasherContract $hasher, $table)
{
$this->connection = $connection;
$this->table = $table;
$this->hasher = $hasher;
public function __construct(
protected ConnectionInterface $connection,
protected HasherContract $hasher,
protected $table,
) {
}

/**
Expand Down
22 changes: 4 additions & 18 deletions src/Illuminate/Auth/EloquentUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@

class EloquentUserProvider implements UserProvider
{
/**
* The hasher implementation.
*
* @var \Illuminate\Contracts\Hashing\Hasher
*/
protected $hasher;

/**
* The Eloquent user model.
*
* @var string
*/
protected $model;

/**
* The callback that may modify the user retrieval queries.
*
Expand All @@ -38,10 +24,10 @@ class EloquentUserProvider implements UserProvider
* @param string $model
* @return void
*/
public function __construct(HasherContract $hasher, $model)
{
$this->model = $model;
$this->hasher = $hasher;
public function __construct(
protected HasherContract $hasher,
protected $model,
) {
}

/**
Expand Down
31 changes: 5 additions & 26 deletions src/Illuminate/Auth/Events/Attempting.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,6 @@

class Attempting
{
/**
* The authentication guard name.
*
* @var string
*/
public $guard;

/**
* The credentials for the user.
*
* @var array
*/
public $credentials;

/**
* Indicates if the user should be "remembered".
*
* @var bool
*/
public $remember;

/**
* Create a new event instance.
*
Expand All @@ -33,10 +12,10 @@ class Attempting
* @param bool $remember
* @return void
*/
public function __construct($guard, #[\SensitiveParameter] $credentials, $remember)
{
$this->guard = $guard;
$this->remember = $remember;
$this->credentials = $credentials;
public function __construct(
public $guard,
#[\SensitiveParameter] public $credentials,
public $remember,
) {
}
}
22 changes: 4 additions & 18 deletions src/Illuminate/Auth/Events/Authenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,16 @@ class Authenticated
{
use SerializesModels;

/**
* The authentication guard name.
*
* @var string
*/
public $guard;

/**
* The authenticated user.
*
* @var \Illuminate\Contracts\Auth\Authenticatable
*/
public $user;

/**
* Create a new event instance.
*
* @param string $guard
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public function __construct($guard, $user)
{
$this->user = $user;
$this->guard = $guard;
public function __construct(
public $guard,
public $user,
) {
}
}
22 changes: 4 additions & 18 deletions src/Illuminate/Auth/Events/CurrentDeviceLogout.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,16 @@ class CurrentDeviceLogout
{
use SerializesModels;

/**
* The authentication guard name.
*
* @var string
*/
public $guard;

/**
* The authenticated user.
*
* @var \Illuminate\Contracts\Auth\Authenticatable
*/
public $user;

/**
* Create a new event instance.
*
* @param string $guard
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public function __construct($guard, $user)
{
$this->user = $user;
$this->guard = $guard;
public function __construct(
public $guard,
public $user,
) {
}
}
31 changes: 5 additions & 26 deletions src/Illuminate/Auth/Events/Failed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,6 @@

class Failed
{
/**
* The authentication guard name.
*
* @var string
*/
public $guard;

/**
* The user the attempter was trying to authenticate as.
*
* @var \Illuminate\Contracts\Auth\Authenticatable|null
*/
public $user;

/**
* The credentials provided by the attempter.
*
* @var array
*/
public $credentials;

/**
* Create a new event instance.
*
Expand All @@ -33,10 +12,10 @@ class Failed
* @param array $credentials
* @return void
*/
public function __construct($guard, $user, #[\SensitiveParameter] $credentials)
{
$this->user = $user;
$this->guard = $guard;
$this->credentials = $credentials;
public function __construct(
public $guard,
public $user,
#[\SensitiveParameter] public $credentials,
) {
}
}
31 changes: 5 additions & 26 deletions src/Illuminate/Auth/Events/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,6 @@ class Login
{
use SerializesModels;

/**
* The authentication guard name.
*
* @var string
*/
public $guard;

/**
* The authenticated user.
*
* @var \Illuminate\Contracts\Auth\Authenticatable
*/
public $user;

/**
* Indicates if the user should be "remembered".
*
* @var bool
*/
public $remember;

/**
* Create a new event instance.
*
Expand All @@ -37,10 +16,10 @@ class Login
* @param bool $remember
* @return void
*/
public function __construct($guard, $user, $remember)
{
$this->user = $user;
$this->guard = $guard;
$this->remember = $remember;
public function __construct(
public $guard,
public $user,
public $remember,
) {
}
}
22 changes: 4 additions & 18 deletions src/Illuminate/Auth/Events/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,16 @@ class Logout
{
use SerializesModels;

/**
* The authentication guard name.
*
* @var string
*/
public $guard;

/**
* The authenticated user.
*
* @var \Illuminate\Contracts\Auth\Authenticatable
*/
public $user;

/**
* Create a new event instance.
*
* @param string $guard
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public function __construct($guard, $user)
{
$this->user = $user;
$this->guard = $guard;
public function __construct(
public $guard,
public $user,
) {
}
}
Loading

0 comments on commit 69b19ce

Please sign in to comment.