0

I am using phpcs with Squiz_Sniffs_Commenting_FunctionCommentSniff, and I get a message error "Expected type hint 'My\Namespace\Interface'; found 'AliasInterface' for $var at position 1.

I declare namespace at top of class adding alias and the method that receives this dependency has type hint using alias. So phpcs show an error about that.

Is there a way to phpcs validation considering alias?

JAL
  • 41,701
  • 23
  • 172
  • 300
fdias
  • 87
  • 5

1 Answers1

0

This reported issue is probably related: https://github.com/squizlabs/PHP_CodeSniffer/issues/325#issuecomment-63166037

Essentially, the sniff doesn't actually look at your imported namespaces. It just checks to ensure the type hint is the same as the type you've declared in the docblock.

In this case of the reported issue, the fully qualified name was being used in the docblock but the alias was being used in the type hint. Maybe you are doing the same thing here.

There is no way to get around this right now. The only way to stop that specific sniff complaining is to ensure the type hint and docblock match. I'm not aware of any other commenting sniffs that will check the same things but support namespace aliasing.

Greg Sherwood
  • 6,992
  • 2
  • 29
  • 24