It is possible to create following rules in php code sniffer?
For example:
Passes:
public function someMethod(SomeIntrerface $foo) : SomeIntrerface
Passes:
/**
* @param SomeIntrerface $foo
* @return SomeIntrerface
*/
public function someMethod($foo)
Do not pass:
public function someMethod($foo)
Pass:
/**
* @var SomeInterface
*/
private $foo;
Do not pass:
private $foo;
Everything is possible, please send a PR.
On the other side I'll suggest an approach that require minimal coding:
@return is already checked by PEAR.Functions.FunctionDeclaration sniffdeclare(strict_types=1) presence (see #911)declare(strict_types=1) in it, that doesn't have types placed would result in an errorFunctionDeclaration sniff mentioned before would check that they're also listed in PHPDocProbably modern IDE (e.g. PhpStorm) will already report missing types as error. If you're using build server adding a lint step would then fail the build if somebody commits such broken code.
Most helpful comment
@LPodolski You can try https://github.com/slevomat/coding-standard/blob/2.0-dev/SlevomatCodingStandard/Sniffs/Typehints/TypeHintDeclarationSniff.php