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] Improve PHPDoc for mapSpread Method in Arr Class & Remove Warning from IDE #51952

Merged
merged 3 commits into from
Jun 28, 2024

Conversation

lmottasin
Copy link
Contributor

Description

This pull request updates the PHPDoc block for the mapSpread method in the Arr class to improve accuracy and clarity. The updated doc block provides more specific type hints for the parameters and return type.

Changes

  • Added @template TKey to indicate the keys are preserved.
  • Updated the @param type for $array to array<TKey, array> to specify the structure of the input array.

Before

/**
 * Run a map over each nested chunk of items.
 *
 * @template TMapSpreadValue
 *
 * @param  array  $array
 * @param  callable(mixed...): TMapSpreadValue  $callback
 * @return array<TKey, TMapSpreadValue>
 */
public static function mapSpread(array $array, callable $callback)
{
    return static::map($array, function ($chunk, $key) use ($callback) {
        $chunk[] = $key;

        return $callback(...$chunk);
    });
}

After

/**
 * Run a map over each nested chunk of items.
 *
 * @template TKey
 * @template TMapSpreadValue
 *
 * @param  array<TKey, array>  $array
 * @param  callable(mixed...): TMapSpreadValue  $callback
 * @return array<TKey, TMapSpreadValue>
 */
public static function mapSpread(array $array, callable $callback)
{
    return static::map($array, function ($chunk, $key) use ($callback) {
        $chunk[] = $key;

        return $callback(...$chunk);
    });
}

@taylorotwell taylorotwell merged commit bbb4678 into laravel:11.x Jun 28, 2024
28 checks passed
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.

3 participants