Skip to content

Add @param string literal union when only literals are passed - #38

Merged
TomasVotruba merged 2 commits into
mainfrom
string-literal-docblock
Sep 25, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
string-literal-docblock

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

When an untyped parameter only ever receives plain string literals, add string plus a @param docblock with the exact values:

+/**
+ * @param 'eq'|'gt'|'neq' $operator
+ */
-public function compareScore(int $score, $operator)
+public function compareScore(int $score, string $operator)

Rules:

  • 2 to 10 distinct literals, single-quoted, sorted
  • null also passed -> ?string + 'a'|'b'|null
  • any non-literal string (constant, sprintf(), interpolation, escapes) skips the docblock
  • a string default must be one of the literals, otherwise skipped
  • existing @param for the parameter is kept; a redundant @param string is replaced
  • only for params argtyper types itself, already typed params are left alone

@TomasVotruba
TomasVotruba merged commit 4282b36 into main Sep 25, 2026
4 checks passed
@TomasVotruba
TomasVotruba deleted the string-literal-docblock branch September 25, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant