Skip to content

Extend RequireArrayShapeReturnRule to positional tuple returns - #369

Merged
TomasVotruba merged 1 commit into
mainfrom
require-array-shape-positional
Oct 14, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
require-array-shape-positional

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Previously the rule flagged only methods whose every return was a literal string-keyed array of 2-3 items. Positional arrays were skipped.

Now it also flags methods whose every return is an all-positional literal array of 2-3 items, suggesting a tuple shape:

public function run(): array
{
    return [$parent, $children];
}

should declare:

/**
 * @return array{0: Parent, 1: Child[]}
 */

Key style must be consistent: all string keys or all positional. Mixed keys, explicit/computed keys and spreads are skipped, as no single clean shape fits. The existing invariant stays - if any return is not a packed literal array (a variable, a call, a plain value), the method is left alone.

  • added ReportPositionalArrayReturn fixture (now reported)
  • added SkipMixedKeyArrayReturn fixture (mixed keys stay skipped)

@TomasVotruba
TomasVotruba merged commit a5e2afe into main Oct 14, 2026
9 checks passed
@TomasVotruba
TomasVotruba deleted the require-array-shape-positional branch October 14, 2026 15:13
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.

1 participant