Skip to content

Use shorthand nullability typings for better readability #5733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/Console/Commands/PublishBackpackMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function getStub()
/**
* Execute the console command.
*
* @return bool|null
* @return ?bool
*/
public function handle()
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/app/Http/Middleware/CheckIfAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/app/Http/Middleware/ThrottlePasswordRecovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/app/Library/Auth/ResetsPasswords.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/app/Library/CrudPanel/CrudButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/app/Library/CrudPanel/CrudField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
4 changes: 2 additions & 2 deletions src/app/Library/CrudPanel/Traits/Buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function buttons()
public function modifyButton($name, $modifications = null)
{
/**
* @var CrudButton|null
* @var ?CrudButton
*/
$button = $this->buttons()->firstWhere('name', $name);

Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/Library/CrudPanel/Traits/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/Library/CrudPanel/Traits/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/Library/CrudPanel/Traits/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function filters()

/**
* @param string $name
* @return null|CrudFilter
* @return ?CrudFilter
*/
public function getFilter($name)
{
Expand Down Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/Library/CrudPanel/Traits/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/app/Library/CrudPanel/Traits/MorphRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/app/Library/CrudPanel/Traits/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/Library/CrudPanel/Traits/SaveActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/app/Library/CrudPanel/Traits/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/app/Library/Uploaders/Support/RegisterUploadEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/app/Library/Validation/Rules/BackpackCustomRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down