Skip to content

Generic/PHPDocTypes and PSR5/PHPDocTypes: Adds sniffs #469

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/Standards/Generic/Docs/Commenting/PHPDocTypesStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<documentation title="PHPDoc Types">
<standard>
<![CDATA[
This sniff aims to check that PHPDoc types will be parsed by both PHPStan and Psalm.
Type checking checks only that the PHPDoc type and native type (if any)
for function parameters and return values, and class properties match.
Type checking is not aware of class heirarchies from other files, or global constants.
]]>
</standard>
<code_comparison>
<code title="Valid: Correct PHPDoc types.">
<![CDATA[
/**
* A class
*/
class C {

/**
* A property
*
* @var int|null
*/
public ?int $prop = 0;

/**
* A function
*
* @param int $p
* @return string
*/
public function f(int $p): string {
return strval($p);
}

}
]]>
</code>
<code title="Invalid: Incorrect PHPDoc types.">
<![CDATA[
/**
* A class
*/
class C {

/**
* A property with a malformed type
*
* @var int||null
*/
public ?int $prop = 0;

/**
* A function
*
* @param $p missing parameter type
* @return int mismatched return type
*/
public function f(int $p): string {
return strval($p);
}

}
]]>
</code>
</code_comparison>
</documentation>
Loading