From bdb018311752b8fd623df10146d22bc692a68533 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Mon, 16 Dec 2024 19:01:15 +0100 Subject: [PATCH 1/2] Use shorthand nullability typings in code for better readability Also remove nullability on registerModelEvents parameter, given that it makes little sense for a boolean value. --- src/app/Library/Uploaders/Support/RegisterUploadEvents.php | 4 ++-- src/app/Library/Validation/Rules/BackpackCustomRule.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/Library/Uploaders/Support/RegisterUploadEvents.php b/src/app/Library/Uploaders/Support/RegisterUploadEvents.php index 3fedbc7175..f54812e077 100644 --- a/src/app/Library/Uploaders/Support/RegisterUploadEvents.php +++ b/src/app/Library/Uploaders/Support/RegisterUploadEvents.php @@ -25,7 +25,7 @@ public function __construct( } } - public static function handle(CrudField|CrudColumn $crudObject, array $uploaderConfiguration, string $macro, ?array $subfield = null, ?bool $registerModelEvents = true): void + public static function handle(CrudField|CrudColumn $crudObject, array $uploaderConfiguration, string $macro, ?array $subfield = null, bool $registerModelEvents = true): void { $instance = new self($crudObject, $uploaderConfiguration, $macro); @@ -35,7 +35,7 @@ public static function handle(CrudField|CrudColumn $crudObject, array $uploaderC /******************************* * Private methods - implementation *******************************/ - private function registerEvents(?array $subfield = [], ?bool $registerModelEvents = true): void + private function registerEvents(?array $subfield = [], bool $registerModelEvents = true): void { if (! empty($subfield)) { $this->registerSubfieldEvent($subfield, $registerModelEvents); diff --git a/src/app/Library/Validation/Rules/BackpackCustomRule.php b/src/app/Library/Validation/Rules/BackpackCustomRule.php index 2807a69c8b..d13680a814 100644 --- a/src/app/Library/Validation/Rules/BackpackCustomRule.php +++ b/src/app/Library/Validation/Rules/BackpackCustomRule.php @@ -178,7 +178,7 @@ protected function validateFieldAndFile(string $attribute, ?array $data = null, /** * Implementation. */ - public function validateFieldRules(string $attribute, null|array|string|UploadedFile $data = null, ?array $customRules = null): array + public function validateFieldRules(string $attribute, array|string|UploadedFile|null $data = null, ?array $customRules = null): array { $data = $data ?? $this->data; $validationRuleAttribute = $this->getValidationAttributeString($attribute); From 904b31e635c3c808fb7b8760caf15900d9ee653d Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Mon, 31 Mar 2025 16:42:35 +0200 Subject: [PATCH 2/2] Use shorthand nullability typings in docblocks for better readability --- src/app/Console/Commands/PublishBackpackMiddleware.php | 2 +- src/app/Http/Controllers/Auth/ResetPasswordController.php | 2 +- src/app/Http/Middleware/CheckIfAdmin.php | 2 +- src/app/Http/Middleware/ThrottlePasswordRecovery.php | 2 +- .../UseBackpackAuthGuardInsteadOfDefaultAuthGuard.php | 2 +- src/app/Library/Auth/ResetsPasswords.php | 2 +- src/app/Library/CrudPanel/CrudButton.php | 2 +- src/app/Library/CrudPanel/CrudField.php | 2 +- src/app/Library/CrudPanel/Traits/Buttons.php | 4 ++-- src/app/Library/CrudPanel/Traits/Create.php | 4 ++-- src/app/Library/CrudPanel/Traits/Fields.php | 2 +- src/app/Library/CrudPanel/Traits/Filters.php | 4 ++-- src/app/Library/CrudPanel/Traits/Input.php | 2 +- src/app/Library/CrudPanel/Traits/MorphRelationships.php | 4 ++-- src/app/Library/CrudPanel/Traits/Query.php | 2 +- src/app/Library/CrudPanel/Traits/SaveActions.php | 2 +- src/app/Library/CrudPanel/Traits/Validation.php | 8 ++++---- 17 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/app/Console/Commands/PublishBackpackMiddleware.php b/src/app/Console/Commands/PublishBackpackMiddleware.php index 714a00ef45..8ac7408cc6 100644 --- a/src/app/Console/Commands/PublishBackpackMiddleware.php +++ b/src/app/Console/Commands/PublishBackpackMiddleware.php @@ -33,7 +33,7 @@ protected function getStub() /** * Execute the console command. * - * @return bool|null + * @return ?bool */ public function handle() { diff --git a/src/app/Http/Controllers/Auth/ResetPasswordController.php b/src/app/Http/Controllers/Auth/ResetPasswordController.php index 48a82c5f92..4ea324aaaa 100644 --- a/src/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/src/app/Http/Controllers/Auth/ResetPasswordController.php @@ -66,7 +66,7 @@ public function __construct() * If no token is present, display the link request form. * * @param \Illuminate\Http\Request $request - * @param string|null $token + * @param ?string $token * @return \Illuminate\Contracts\View\View */ public function showResetForm(Request $request, $token = null) diff --git a/src/app/Http/Middleware/CheckIfAdmin.php b/src/app/Http/Middleware/CheckIfAdmin.php index fb737d0262..a8c197e8aa 100644 --- a/src/app/Http/Middleware/CheckIfAdmin.php +++ b/src/app/Http/Middleware/CheckIfAdmin.php @@ -22,7 +22,7 @@ class CheckIfAdmin * does not have a '/home' route, use something you've built for your users * (again - users, not admins). * - * @param \Illuminate\Contracts\Auth\Authenticatable|null $user + * @param ?\Illuminate\Contracts\Auth\Authenticatable $user * @return bool */ private function checkIfUserIsAdmin($user) diff --git a/src/app/Http/Middleware/ThrottlePasswordRecovery.php b/src/app/Http/Middleware/ThrottlePasswordRecovery.php index 9e26fa63fc..81751ff318 100644 --- a/src/app/Http/Middleware/ThrottlePasswordRecovery.php +++ b/src/app/Http/Middleware/ThrottlePasswordRecovery.php @@ -13,7 +13,7 @@ class ThrottlePasswordRecovery extends ThrottleRequests * @param \Illuminate\Http\Request $request * @param string $key * @param int $maxAttempts - * @param callable|null $responseCallback + * @param ?callable $responseCallback * @return \Illuminate\Validation\ValidationException */ protected function buildException($request, $key, $maxAttempts, $responseCallback = null) diff --git a/src/app/Http/Middleware/UseBackpackAuthGuardInsteadOfDefaultAuthGuard.php b/src/app/Http/Middleware/UseBackpackAuthGuardInsteadOfDefaultAuthGuard.php index 5713b09112..4538da3066 100644 --- a/src/app/Http/Middleware/UseBackpackAuthGuardInsteadOfDefaultAuthGuard.php +++ b/src/app/Http/Middleware/UseBackpackAuthGuardInsteadOfDefaultAuthGuard.php @@ -11,7 +11,7 @@ class UseBackpackAuthGuardInsteadOfDefaultAuthGuard * * @param \Illuminate\Http\Request $request * @param \Closure $next - * @param string|null $guard + * @param ?string $guard * @return mixed */ public function handle($request, Closure $next, $guard = null) diff --git a/src/app/Library/Auth/ResetsPasswords.php b/src/app/Library/Auth/ResetsPasswords.php index 1d28c3ba1e..33bfae2ef8 100644 --- a/src/app/Library/Auth/ResetsPasswords.php +++ b/src/app/Library/Auth/ResetsPasswords.php @@ -21,7 +21,7 @@ trait ResetsPasswords * If no token is present, display the link request form. * * @param \Illuminate\Http\Request $request - * @param string|null $token + * @param ?string $token * @return \Illuminate\Contracts\View\View */ public function showResetForm(Request $request, $token = null) diff --git a/src/app/Library/CrudPanel/CrudButton.php b/src/app/Library/CrudPanel/CrudButton.php index e34bd0ca09..ba4c8ef6ed 100644 --- a/src/app/Library/CrudPanel/CrudButton.php +++ b/src/app/Library/CrudPanel/CrudButton.php @@ -294,7 +294,7 @@ public function section($stack) * Get the end result that should be displayed to the user. * The HTML itself of the button. * - * @param object|null $entry The eloquent Model for the current entry or null if no current entry. + * @param ?object $entry The eloquent Model for the current entry or null if no current entry. * @return \Illuminate\Contracts\View\View */ public function getHtml($entry = null) diff --git a/src/app/Library/CrudPanel/CrudField.php b/src/app/Library/CrudPanel/CrudField.php index 2877b79f7e..eb1c46748c 100644 --- a/src/app/Library/CrudPanel/CrudField.php +++ b/src/app/Library/CrudPanel/CrudField.php @@ -299,7 +299,7 @@ public function validationMessages(array $messages) * ->addMorphOption('App\Models\Model', 'label', ['data_source' => backpack_url('smt')]). * * @param string $key - the morph option key, usually a \Model\Class or a string for the morphMap - * @param string|null $label - the displayed text for this option + * @param ?string $label - the displayed text for this option * @param array $options - options for the corresponding morphable_id field (usually ajax options) * @return self * diff --git a/src/app/Library/CrudPanel/Traits/Buttons.php b/src/app/Library/CrudPanel/Traits/Buttons.php index 12d8412d38..0dea70b0da 100644 --- a/src/app/Library/CrudPanel/Traits/Buttons.php +++ b/src/app/Library/CrudPanel/Traits/Buttons.php @@ -112,7 +112,7 @@ public function buttons() public function modifyButton($name, $modifications = null) { /** - * @var CrudButton|null + * @var ?CrudButton */ $button = $this->buttons()->firstWhere('name', $name); @@ -144,7 +144,7 @@ public function removeButton($name, $stack = null) /** * @param array $names Button names - * @param string|null $stack Optional stack name. + * @param ?string $stack Optional stack name. */ public function removeButtons($names, $stack = null) { diff --git a/src/app/Library/CrudPanel/Traits/Create.php b/src/app/Library/CrudPanel/Traits/Create.php index aa909e2a82..cde0fe049f 100644 --- a/src/app/Library/CrudPanel/Traits/Create.php +++ b/src/app/Library/CrudPanel/Traits/Create.php @@ -99,7 +99,7 @@ public function getRelationFields($fields = []) * * @param Model $item The current CRUD model. * @param array $formattedRelations The form data. - * @return bool|null + * @return ?bool */ private function createRelationsForItem($item, $formattedRelations) { @@ -220,7 +220,7 @@ private function preparePivotAttributesForSave(array $attributes, BelongsToMany| * 'attribute' => 'passport', * 'values' => **THE TRICKY BIT**, * ] - * @return Model|null + * @return ?Model */ private function createUpdateOrDeleteOneToOneRelation($relation, $relationMethod, $relationDetails) { diff --git a/src/app/Library/CrudPanel/Traits/Fields.php b/src/app/Library/CrudPanel/Traits/Fields.php index ab851d9e25..455b66779f 100644 --- a/src/app/Library/CrudPanel/Traits/Fields.php +++ b/src/app/Library/CrudPanel/Traits/Fields.php @@ -156,7 +156,7 @@ public function beforeField($targetFieldName) /** * Move this field to be first in the fields list. * - * @return bool|null + * @return ?bool */ public function makeFirstField() { diff --git a/src/app/Library/CrudPanel/Traits/Filters.php b/src/app/Library/CrudPanel/Traits/Filters.php index 34f08d4457..4b121e65a2 100644 --- a/src/app/Library/CrudPanel/Traits/Filters.php +++ b/src/app/Library/CrudPanel/Traits/Filters.php @@ -136,7 +136,7 @@ public function filters() /** * @param string $name - * @return null|CrudFilter + * @return ?CrudFilter */ public function getFilter($name) { @@ -234,7 +234,7 @@ public function beforeFilter($destination) /** * Move this filter to be first in the columns list. * - * @return bool|null + * @return ?bool */ public function makeFirstFilter() { diff --git a/src/app/Library/CrudPanel/Traits/Input.php b/src/app/Library/CrudPanel/Traits/Input.php index 9e58f04db3..8b515400b1 100644 --- a/src/app/Library/CrudPanel/Traits/Input.php +++ b/src/app/Library/CrudPanel/Traits/Input.php @@ -17,7 +17,7 @@ trait Input * Returns the direct inputs parsed for model and relationship creation. * * @param array $inputs - * @param null|array $relationDetails + * @param ?array $relationDetails * @param bool|string $relationMethod * @return array */ diff --git a/src/app/Library/CrudPanel/Traits/MorphRelationships.php b/src/app/Library/CrudPanel/Traits/MorphRelationships.php index c3db93b745..7b18bc5278 100644 --- a/src/app/Library/CrudPanel/Traits/MorphRelationships.php +++ b/src/app/Library/CrudPanel/Traits/MorphRelationships.php @@ -84,7 +84,7 @@ private function makeSureMorphSubfieldsAreDefined(array $field) * * @param string|array $fieldOrName - The field array or the field name * @param string $key - the morph option key, usually a \Model\Class or a string for the morphMap - * @param string|null $label - the displayed text for this option + * @param ?string $label - the displayed text for this option * @param array $options - options for the corresponding morphable_id field (usually ajax options) * @return void|array */ @@ -130,7 +130,7 @@ public function addMorphOption($fieldOrName, string $key, $label = null, array $ * * @param array $morphTypeField * @param string $key - * @param string|null $label + * @param ?string $label * @return array */ private function getMorphTypeFieldWithOptions(array $morphTypeField, string $key, $label) diff --git a/src/app/Library/CrudPanel/Traits/Query.php b/src/app/Library/CrudPanel/Traits/Query.php index a14d3817c5..1b9bb127db 100644 --- a/src/app/Library/CrudPanel/Traits/Query.php +++ b/src/app/Library/CrudPanel/Traits/Query.php @@ -220,7 +220,7 @@ public function getQueryCount() /** * Return the filtered query count or skip the counting when the `totalQuery` is the same as the filtered one. * - * @return int|null + * @return ?int */ public function getFilteredQueryCount() { diff --git a/src/app/Library/CrudPanel/Traits/SaveActions.php b/src/app/Library/CrudPanel/Traits/SaveActions.php index 91db553612..33ce247371 100644 --- a/src/app/Library/CrudPanel/Traits/SaveActions.php +++ b/src/app/Library/CrudPanel/Traits/SaveActions.php @@ -299,7 +299,7 @@ public function getSaveAction() /** * Change the session variable that remembers what to do after the "Save" action. * - * @param string|null $forceSaveAction + * @param ?string $forceSaveAction * @return void */ public function setSaveAction($forceSaveAction = null) diff --git a/src/app/Library/CrudPanel/Traits/Validation.php b/src/app/Library/CrudPanel/Traits/Validation.php index 23ca6091b4..5a4a9df89e 100644 --- a/src/app/Library/CrudPanel/Traits/Validation.php +++ b/src/app/Library/CrudPanel/Traits/Validation.php @@ -154,9 +154,9 @@ public function validateRequest() * Merge the form request validation with the fields validation. * * @param FormRequest $request - * @param array|null $rules - * @param array|null $messages - * @param array|null $attributes + * @param ?array $rules + * @param ?array $messages + * @param ?array $attributes * @return array */ public function mergeRequestAndFieldRules($request, $rules = null, $messages = null, $attributes = null) @@ -445,7 +445,7 @@ private function getRequestRulesAsArray($request) * * @param array $rules * @param array $messages - * @param \Illuminate\Http\Request|null $request + * @param ?\Illuminate\Http\Request $request * @return \Illuminate\Http\Request */ private function checkRequestValidity($rules, $messages, $attributes, $request = null)