Skip to content
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

[11.x] Modify doc blocks for getGateArguments #50874

Merged
merged 1 commit into from
Apr 1, 2024

Conversation

saMahmoudzadeh
Copy link
Contributor

This PR, fixes @return for getGateArguments method in Authorize.php

// Before
 /**
   * Get the arguments parameter for the gate.
   *
   * @param  \Illuminate\Http\Request  $request
   * @param  array|null  $models
   * @return \Illuminate\Database\Eloquent\Model|array|string
   */
  protected function getGateArguments($request, $models)
  {
      if (is_null($models)) {
          return [];
      }

      return collect($models)->map(function ($model) use ($request) {
          return $model instanceof Model ? $model : $this->getModel($request, $model);
      })->all();
  }

If $models is null in the getGateArguments method, an empty array is returned; otherwise, an array is still returned because the all() method in collections returns an array.

/**
   * Get all of the items in the collection.
   *
   * @return array<TKey, TValue>
   */
  public function all()
  {
      return $this->items;
  }

In the all() method, $this->items is always an array. Therefore, we can change the @return for the getGateArguments method to an array.

// After
 /**
   * Get the arguments parameter for the gate.
   *
   * @param  \Illuminate\Http\Request  $request
   * @param  array|null  $models
   * @return array
   */

@taylorotwell taylorotwell merged commit 73ed300 into laravel:11.x Apr 1, 2024
28 of 30 checks passed
@saMahmoudzadeh saMahmoudzadeh deleted the fix/authorize-doc-block branch April 1, 2024 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants