Add nullable_type_declaration_for_default_null_value rule

This commit is contained in:
Lance Pioch 2024-10-19 18:41:08 -04:00
parent 96acd268be
commit 1bf6a880fb
34 changed files with 37 additions and 38 deletions

View File

@ -10,7 +10,7 @@ class HttpForbiddenException extends HttpException
/** /**
* HttpForbiddenException constructor. * HttpForbiddenException constructor.
*/ */
public function __construct(string $message = null, \Throwable $previous = null) public function __construct(?string $message = null, ?\Throwable $previous = null)
{ {
parent::__construct(Response::HTTP_FORBIDDEN, $message, $previous); parent::__construct(Response::HTTP_FORBIDDEN, $message, $previous);
} }

View File

@ -12,7 +12,7 @@ class ServerStateConflictException extends ConflictHttpException
* Exception thrown when the server is in an unsupported state for API access or * Exception thrown when the server is in an unsupported state for API access or
* certain operations within the codebase. * certain operations within the codebase.
*/ */
public function __construct(Server $server, \Throwable $previous = null) public function __construct(Server $server, ?\Throwable $previous = null)
{ {
$message = 'This server is currently in an unsupported state, please try again later.'; $message = 'This server is currently in an unsupported state, please try again later.';
if ($server->isSuspended()) { if ($server->isSuspended()) {

View File

@ -11,7 +11,7 @@ class TwoFactorAuthRequiredException extends HttpException implements HttpExcept
/** /**
* TwoFactorAuthRequiredException constructor. * TwoFactorAuthRequiredException constructor.
*/ */
public function __construct(\Throwable $previous = null) public function __construct(?\Throwable $previous = null)
{ {
parent::__construct(Response::HTTP_BAD_REQUEST, 'Two-factor authentication is required on this account in order to access this endpoint.', $previous); parent::__construct(Response::HTTP_BAD_REQUEST, 'Two-factor authentication is required on this account in order to access this endpoint.', $previous);
} }

View File

@ -10,7 +10,7 @@ class ServiceLimitExceededException extends DisplayException
* Exception thrown when something goes over a defined limit, such as allocated * Exception thrown when something goes over a defined limit, such as allocated
* ports, tasks, databases, etc. * ports, tasks, databases, etc.
*/ */
public function __construct(string $message, \Throwable $previous = null) public function __construct(string $message, ?\Throwable $previous = null)
{ {
parent::__construct($message, $previous, self::LEVEL_WARNING); parent::__construct($message, $previous, self::LEVEL_WARNING);
} }

View File

@ -34,7 +34,7 @@ class BackupManager
/** /**
* Returns a backup adapter instance. * Returns a backup adapter instance.
*/ */
public function adapter(string $name = null): FilesystemAdapter public function adapter(?string $name = null): FilesystemAdapter
{ {
return $this->get($name ?: $this->getDefaultAdapter()); return $this->get($name ?: $this->getDefaultAdapter());
} }

View File

@ -127,7 +127,7 @@ class EggController extends Controller
/** /**
* Normalizes a string of docker image data into the expected egg format. * Normalizes a string of docker image data into the expected egg format.
*/ */
protected function normalizeDockerImages(string $input = null): array protected function normalizeDockerImages(?string $input = null): array
{ {
$data = array_map(fn ($value) => trim($value), explode("\n", $input ?? '')); $data = array_map(fn ($value) => trim($value), explode("\n", $input ?? ''));

View File

@ -51,7 +51,7 @@ abstract class AbstractLoginController extends Controller
* *
* @throws \App\Exceptions\DisplayException * @throws \App\Exceptions\DisplayException
*/ */
protected function sendFailedLoginResponse(Request $request, Authenticatable $user = null, string $message = null) protected function sendFailedLoginResponse(Request $request, ?Authenticatable $user = null, ?string $message = null)
{ {
$this->incrementLoginAttempts($request); $this->incrementLoginAttempts($request);
$this->fireFailedLoginEvent($user, [ $this->fireFailedLoginEvent($user, [
@ -91,7 +91,7 @@ abstract class AbstractLoginController extends Controller
/** /**
* Determine if the user is logging in using an email or username. * Determine if the user is logging in using an email or username.
*/ */
protected function getField(string $input = null): string protected function getField(?string $input = null): string
{ {
return ($input && str_contains($input, '@')) ? 'email' : 'username'; return ($input && str_contains($input, '@')) ? 'email' : 'username';
} }
@ -99,7 +99,7 @@ abstract class AbstractLoginController extends Controller
/** /**
* Fire a failed login event. * Fire a failed login event.
*/ */
protected function fireFailedLoginEvent(Authenticatable $user = null, array $credentials = []) protected function fireFailedLoginEvent(?Authenticatable $user = null, array $credentials = [])
{ {
Event::dispatch(new Failed('auth', $user, $credentials)); Event::dispatch(new Failed('auth', $user, $credentials));
} }

View File

@ -17,7 +17,7 @@ class RedirectIfAuthenticated
/** /**
* Handle an incoming request. * Handle an incoming request.
*/ */
public function handle(Request $request, \Closure $next, string $guard = null): mixed public function handle(Request $request, \Closure $next, ?string $guard = null): mixed
{ {
if ($this->authManager->guard($guard)->check()) { if ($this->authManager->guard($guard)->check()) {
return redirect()->route('index'); return redirect()->route('index');

View File

@ -28,7 +28,7 @@ abstract class AdminFormRequest extends FormRequest
* Return only the fields that we are interested in from the request. * Return only the fields that we are interested in from the request.
* This will include empty fields as a null value. * This will include empty fields as a null value.
*/ */
public function normalize(array $only = null): array public function normalize(?array $only = null): array
{ {
return $this->only($only ?? array_keys($this->rules())); return $this->only($only ?? array_keys($this->rules()));
} }

View File

@ -27,7 +27,7 @@ class MailSettingsFormRequest extends AdminFormRequest
* Override the default normalization function for this type of request * Override the default normalization function for this type of request
* as we need to accept empty values on the keys. * as we need to accept empty values on the keys.
*/ */
public function normalize(array $only = null): array public function normalize(?array $only = null): array
{ {
$keys = array_flip(array_keys($this->rules())); $keys = array_flip(array_keys($this->rules()));

View File

@ -12,7 +12,7 @@ class StoreDatabaseHostRequest extends ApplicationApiRequest
protected int $permission = AdminAcl::WRITE; protected int $permission = AdminAcl::WRITE;
public function rules(array $rules = null): array public function rules(?array $rules = null): array
{ {
return $rules ?? DatabaseHost::getRules(); return $rules ?? DatabaseHost::getRules();
} }

View File

@ -6,7 +6,7 @@ use App\Models\DatabaseHost;
class UpdateDatabaseHostRequest extends StoreDatabaseHostRequest class UpdateDatabaseHostRequest extends StoreDatabaseHostRequest
{ {
public function rules(array $rules = null): array public function rules(?array $rules = null): array
{ {
/** @var DatabaseHost $databaseHost */ /** @var DatabaseHost $databaseHost */
$databaseHost = $this->route()->parameter('database_host'); $databaseHost = $this->route()->parameter('database_host');

View File

@ -9,7 +9,7 @@ class UpdateMountRequest extends StoreMountRequest
/** /**
* Apply validation rules to this request. * Apply validation rules to this request.
*/ */
public function rules(array $rules = null): array public function rules(?array $rules = null): array
{ {
/** @var Mount $mount */ /** @var Mount $mount */
$mount = $this->route()->parameter('mount'); $mount = $this->route()->parameter('mount');

View File

@ -15,7 +15,7 @@ class StoreNodeRequest extends ApplicationApiRequest
/** /**
* Validation rules to apply to this request. * Validation rules to apply to this request.
*/ */
public function rules(array $rules = null): array public function rules(?array $rules = null): array
{ {
return collect($rules ?? Node::getRules())->only([ return collect($rules ?? Node::getRules())->only([
'public', 'public',

View File

@ -10,7 +10,7 @@ class UpdateNodeRequest extends StoreNodeRequest
* Apply validation rules to this request. Uses the parent class rules() * Apply validation rules to this request. Uses the parent class rules()
* function but passes in the rules for updating rather than creating. * function but passes in the rules for updating rather than creating.
*/ */
public function rules(array $rules = null): array public function rules(?array $rules = null): array
{ {
/** @var Node $node */ /** @var Node $node */
$node = $this->route()->parameter('node'); $node = $this->route()->parameter('node');

View File

@ -11,7 +11,7 @@ class StoreRoleRequest extends ApplicationApiRequest
protected int $permission = AdminAcl::WRITE; protected int $permission = AdminAcl::WRITE;
public function rules(array $rules = null): array public function rules(?array $rules = null): array
{ {
return [ return [
'name' => 'required|string', 'name' => 'required|string',

View File

@ -7,7 +7,7 @@ class AssignUserRolesRequest extends StoreUserRequest
/** /**
* Return the validation rules for this request. * Return the validation rules for this request.
*/ */
public function rules(array $rules = null): array public function rules(?array $rules = null): array
{ {
return [ return [
'roles' => 'array', 'roles' => 'array',

View File

@ -15,7 +15,7 @@ class StoreUserRequest extends ApplicationApiRequest
/** /**
* Return the validation rules for this request. * Return the validation rules for this request.
*/ */
public function rules(array $rules = null): array public function rules(?array $rules = null): array
{ {
$rules = $rules ?? User::getRules(); $rules = $rules ?? User::getRules();

View File

@ -9,7 +9,7 @@ class UpdateUserRequest extends StoreUserRequest
/** /**
* Return the validation rules for this request. * Return the validation rules for this request.
*/ */
public function rules(array $rules = null): array public function rules(?array $rules = null): array
{ {
$userId = $this->parameter('user', User::class)->id; $userId = $this->parameter('user', User::class)->id;

View File

@ -90,7 +90,7 @@ class RunTaskJob extends Job implements ShouldQueue
/** /**
* Handle a failure while sending the action to the daemon or otherwise processing the job. * Handle a failure while sending the action to the daemon or otherwise processing the job.
*/ */
public function failed(\Exception $exception = null) public function failed(?\Exception $exception = null)
{ {
$this->markTaskNotQueued(); $this->markTaskNotQueued();
$this->markScheduleComplete(); $this->markScheduleComplete();

View File

@ -50,7 +50,7 @@ class DaemonBackupRepository extends DaemonRepository
* *
* @throws \App\Exceptions\Http\Connection\DaemonConnectionException * @throws \App\Exceptions\Http\Connection\DaemonConnectionException
*/ */
public function restore(Backup $backup, string $url = null, bool $truncate = false) public function restore(Backup $backup, ?string $url = null, bool $truncate = false)
{ {
Assert::isInstanceOf($this->server, Server::class); Assert::isInstanceOf($this->server, Server::class);

View File

@ -21,7 +21,7 @@ class DaemonFileRepository extends DaemonRepository
* @throws \App\Exceptions\Http\Server\FileSizeTooLargeException * @throws \App\Exceptions\Http\Server\FileSizeTooLargeException
* @throws \App\Exceptions\Http\Connection\DaemonConnectionException * @throws \App\Exceptions\Http\Connection\DaemonConnectionException
*/ */
public function getContent(string $path, int $notLargerThan = null): string public function getContent(string $path, ?int $notLargerThan = null): string
{ {
Assert::isInstanceOf($this->server, Server::class); Assert::isInstanceOf($this->server, Server::class);

View File

@ -130,7 +130,7 @@ class ActivityLogService
* performing this action it will be logged to the disk but will not interrupt * performing this action it will be logged to the disk but will not interrupt
* the code flow. * the code flow.
*/ */
public function log(string $description = null): ActivityLog public function log(?string $description = null): ActivityLog
{ {
$activity = $this->getActivity(); $activity = $this->getActivity();

View File

@ -43,7 +43,7 @@ class AssignmentService
* @throws \App\Exceptions\Service\Allocation\PortOutOfRangeException * @throws \App\Exceptions\Service\Allocation\PortOutOfRangeException
* @throws \App\Exceptions\Service\Allocation\TooManyPortsInRangeException * @throws \App\Exceptions\Service\Allocation\TooManyPortsInRangeException
*/ */
public function handle(Node $node, array $data, Server $server = null): array public function handle(Node $node, array $data, ?Server $server = null): array
{ {
$explode = explode('/', $data['allocation_ip']); $explode = explode('/', $data['allocation_ip']);
if (count($explode) !== 1) { if (count($explode) !== 1) {

View File

@ -70,7 +70,7 @@ class InitiateBackupService
* @throws \App\Exceptions\Service\Backup\TooManyBackupsException * @throws \App\Exceptions\Service\Backup\TooManyBackupsException
* @throws \Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException * @throws \Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException
*/ */
public function handle(Server $server, string $name = null, bool $override = false): Backup public function handle(Server $server, ?string $name = null, bool $override = false): Backup
{ {
$limit = config('backups.throttles.limit'); $limit = config('backups.throttles.limit');
$period = config('backups.throttles.period'); $period = config('backups.throttles.period');

View File

@ -34,7 +34,7 @@ class EggImporterService
* *
* @throws \App\Exceptions\Service\InvalidFileUploadException|\Throwable * @throws \App\Exceptions\Service\InvalidFileUploadException|\Throwable
*/ */
public function fromFile(UploadedFile $file, Egg $egg = null): Egg public function fromFile(UploadedFile $file, ?Egg $egg = null): Egg
{ {
$parsed = $this->parseFile($file); $parsed = $this->parseFile($file);
@ -75,7 +75,7 @@ class EggImporterService
* *
* @throws \App\Exceptions\Service\InvalidFileUploadException|\Throwable * @throws \App\Exceptions\Service\InvalidFileUploadException|\Throwable
*/ */
public function fromUrl(string $url, Egg $egg = null): Egg public function fromUrl(string $url, ?Egg $egg = null): Egg
{ {
$info = pathinfo($url); $info = pathinfo($url);
$tmpDir = TemporaryDirectory::make()->deleteWhenDestroyed(); $tmpDir = TemporaryDirectory::make()->deleteWhenDestroyed();

View File

@ -45,7 +45,7 @@ class ServerCreationService
* @throws \Illuminate\Validation\ValidationException * @throws \Illuminate\Validation\ValidationException
* @throws \App\Exceptions\Service\Deployment\NoViableAllocationException * @throws \App\Exceptions\Service\Deployment\NoViableAllocationException
*/ */
public function handle(array $data, DeploymentObject $deployment = null): Server public function handle(array $data, ?DeploymentObject $deployment = null): Server
{ {
if (!isset($data['oom_killer']) && isset($data['oom_disabled'])) { if (!isset($data['oom_killer']) && isset($data['oom_disabled'])) {
$data['oom_killer'] = !$data['oom_disabled']; $data['oom_killer'] = !$data['oom_disabled'];

View File

@ -30,7 +30,7 @@ class ToggleTwoFactorService
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException * @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
* @throws \App\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid * @throws \App\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid
*/ */
public function handle(User $user, string $token, bool $toggleState = null): array public function handle(User $user, string $token, ?bool $toggleState = null): array
{ {
$isValidToken = $this->google2FA->verifyKey($user->totp_secret, $token, config()->get('panel.auth.2fa.window')); $isValidToken = $this->google2FA->verifyKey($user->totp_secret, $token, config()->get('panel.auth.2fa.window'));

View File

@ -111,7 +111,7 @@ class ActivityLogTransformer extends BaseClientTransformer
* Determines if the user can view the IP address in the output either because they are the * Determines if the user can view the IP address in the output either because they are the
* actor that performed the action, or because they are an administrator on the Panel. * actor that performed the action, or because they are an administrator on the Panel.
*/ */
protected function canViewIP(Model $actor = null): bool protected function canViewIP(?Model $actor = null): bool
{ {
return $actor?->is($this->request->user()) || $this->request->user()->isRootAdmin(); return $actor?->is($this->request->user()) || $this->request->user()->isRootAdmin();
} }

View File

@ -24,7 +24,7 @@ abstract class BaseClientTransformer extends BaseApplicationTransformer
* *
* @noinspection PhpParameterNameChangedDuringInheritanceInspection * @noinspection PhpParameterNameChangedDuringInheritanceInspection
*/ */
protected function authorize(string $ability, Server $server = null): bool protected function authorize(string $ability, ?Server $server = null): bool
{ {
Assert::isInstanceOf($server, Server::class); Assert::isInstanceOf($server, Server::class);

View File

@ -2,7 +2,6 @@
"preset": "laravel", "preset": "laravel",
"rules": { "rules": {
"not_operator_with_successor_space": false, "not_operator_with_successor_space": false,
"nullable_type_declaration_for_default_null_value": false,
"ordered_imports": false, "ordered_imports": false,
"phpdoc_align": false, "phpdoc_align": false,
"phpdoc_separation": false "phpdoc_separation": false

View File

@ -47,7 +47,7 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
/** /**
* Returns a link to the specific resource using the client API. * Returns a link to the specific resource using the client API.
*/ */
protected function link(mixed $model, string $append = null): string protected function link(mixed $model, ?string $append = null): string
{ {
switch (get_class($model)) { switch (get_class($model)) {
case Server::class: case Server::class:

View File

@ -226,7 +226,7 @@ class SftpAuthenticationControllerTest extends IntegrationTestCase
/** /**
* Sets the authorization header for the rest of the test. * Sets the authorization header for the rest of the test.
*/ */
protected function setAuthorization(Node $node = null): void protected function setAuthorization(?Node $node = null): void
{ {
$node = $node ?? $this->server->node; $node = $node ?? $this->server->node;

View File

@ -27,7 +27,7 @@ trait RequestMockHelpers
/** /**
* Configure the user model that the request mock should return with. * Configure the user model that the request mock should return with.
*/ */
public function setRequestUserModel(User $user = null): void public function setRequestUserModel(?User $user = null): void
{ {
$this->request->shouldReceive('user')->andReturn($user); $this->request->shouldReceive('user')->andReturn($user);
} }
@ -80,7 +80,7 @@ trait RequestMockHelpers
* *
* @deprecated * @deprecated
*/ */
protected function setRequestUser(User $user = null): User protected function setRequestUser(?User $user = null): User
{ {
$user = $user instanceof User ? $user : User::factory()->make(); $user = $user instanceof User ? $user : User::factory()->make();
$this->request->shouldReceive('user')->withNoArgs()->andReturn($user); $this->request->shouldReceive('user')->withNoArgs()->andReturn($user);