Skip to content

Only allow useful @param and @return annotations #17

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

Merged
merged 3 commits into from
Nov 9, 2018

Conversation

nicwortel
Copy link
Contributor

@nicwortel nicwortel commented Nov 9, 2018

This disallows the use of individual @param and @return annotations when PHP type declarations already provide sufficient information.

Instead of requiring that all parameters and the return type are documented:

/**
 * @param string $stringA
 * @param string $stringB
 * @param int[]  $numbers
 *
 * @return void
 */
public function documentAllTheThings(string $stringA, string $stringB, array $numbers): void
{
}

...this allows (and even enforces) that only "useful" annotations are used:

/**
 * @param int[] $numbers
 */
public function onlyUsefulAnnotations(string $stringA, string $stringB, array $numbers): void
{
}

This way, we can keep our codebase "clean" with only the docblock annotations we really need.

The violations can be automatically fixed by CodeSniffer using the vendor/bin/phpcbf command, but that may leave behind some trailing blank lines in docblocks, so some manual care is recommended.

@nicwortel nicwortel changed the title Only allow useful type annotations Only allow useful @param and @return annotations Nov 9, 2018
If PHP type declarations can be used to describe the type of a parameter or return value, we shouldn't have to duplicate this in a docblock annotation.
This forbids the use of @param and @return annotations where PHP type declarations provide sufficient information.
Copy link
Contributor

@denniscoorn denniscoorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦄

@nicwortel nicwortel merged commit 385a802 into master Nov 9, 2018
@nicwortel nicwortel deleted the only-allow-useful-type-annotations branch November 9, 2018 14:44
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.

6 participants